feat(api): add reviews module with CRUD endpoints and CQRS
Implement polymorphic reviews system supporting any target type (agent, property, etc.) with DDD/CQRS architecture following existing patterns. Endpoints: - POST /api/reviews — create review (authenticated) - GET /api/reviews?targetType=&targetId= — list reviews by target - GET /api/reviews/stats?targetType=&targetId= — aggregate rating stats - GET /api/reviews/me — list authenticated user's reviews - DELETE /api/reviews/:id — delete own review Business rules: 1-5 rating validation, self-review prevention, one review per user per target. Includes 15 unit tests for all handlers. Co-Authored-By: Paperclip <noreply@paperclip.ing>
This commit is contained in:
@@ -0,0 +1,26 @@
|
||||
import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger';
|
||||
import { IsInt, IsNotEmpty, IsOptional, IsString, Max, MaxLength, Min } from 'class-validator';
|
||||
|
||||
export class CreateReviewDto {
|
||||
@ApiProperty({ example: 'agent', description: 'Target entity type (e.g. agent, property)' })
|
||||
@IsString()
|
||||
@IsNotEmpty()
|
||||
targetType!: string;
|
||||
|
||||
@ApiProperty({ example: 'clxyz123', description: 'Target entity ID' })
|
||||
@IsString()
|
||||
@IsNotEmpty()
|
||||
targetId!: string;
|
||||
|
||||
@ApiProperty({ example: 5, description: 'Rating from 1 to 5', minimum: 1, maximum: 5 })
|
||||
@IsInt()
|
||||
@Min(1)
|
||||
@Max(5)
|
||||
rating!: number;
|
||||
|
||||
@ApiPropertyOptional({ example: 'Dịch vụ rất tốt!', description: 'Optional review comment' })
|
||||
@IsOptional()
|
||||
@IsString()
|
||||
@MaxLength(2000)
|
||||
comment?: string;
|
||||
}
|
||||
Reference in New Issue
Block a user