review
This commit is contained in:
@@ -34,37 +34,24 @@ export class ReviewController {
|
||||
@Post('public/reviews')
|
||||
@ApiOperation({ summary: 'Create a new review and rating' })
|
||||
@ApiHeader(API_HEADER_SLUG)
|
||||
@ApiCreatedResponse({ description: 'The review has been successfully created.' })
|
||||
@ApiBody({ type: CreateReviewDto })
|
||||
create(@Body() createReviewDto: CreateReviewDto, @UserId() userId: string) {
|
||||
return this.reviewService.create(userId, createReviewDto);
|
||||
}
|
||||
|
||||
@Get('public/reviews/:foodId')
|
||||
@Get('public/reviews/product/:id')
|
||||
@ApiOperation({ summary: 'Get all reviews of product by id(public - only approved)' })
|
||||
@ApiHeader(API_HEADER_SLUG)
|
||||
@ApiOkResponse({ description: 'List of approved reviews' })
|
||||
@ApiParam({ name: 'foodId', required: true, type: String })
|
||||
@ApiQuery({ name: 'page', required: false, type: Number })
|
||||
@ApiQuery({ name: 'limit', required: false, type: Number })
|
||||
@ApiQuery({ name: 'orderBy', required: false, type: String })
|
||||
@ApiQuery({ name: 'order', required: false, enum: ['asc', 'desc'] })
|
||||
findAll(@Query() dto: FindReviewsDto, @Param('foodId') foodId: string) {
|
||||
findAll(@Query() dto: FindReviewsDto, @Param('id') id: string) {
|
||||
// Only show approved reviews for public endpoint
|
||||
return this.reviewService.findAll({ ...dto, status: ReviewStatus.APPROVED, foodId });
|
||||
return this.reviewService.findAll({ ...dto, status: ReviewStatus.APPROVED, productId: id });
|
||||
}
|
||||
|
||||
@Get('public/reviews/restuarant/:restuarantSlug')
|
||||
@ApiOperation({ summary: 'Get all reviews of restuarant by slug(public - only approved)' })
|
||||
@Get('public/reviews/shop/:shopSlug')
|
||||
@ApiOperation({ summary: 'Get all reviews of shop by slug(public - only approved)' })
|
||||
@ApiHeader(API_HEADER_SLUG)
|
||||
@ApiParam({ name: 'restuarantSlug', required: true, type: String })
|
||||
@ApiQuery({ name: 'page', required: false, type: Number })
|
||||
@ApiQuery({ name: 'limit', required: false, type: Number })
|
||||
@ApiQuery({ name: 'orderBy', required: false, type: String })
|
||||
@ApiQuery({ name: 'order', required: false, enum: ['asc', 'desc'] })
|
||||
findRestuarantAllReviews(@Query() dto: FindRestuarantReviewsDto, @Param('restuarantSlug') restuarantSlug: string) {
|
||||
findRestuarantAllReviews(@Query() dto: FindRestuarantReviewsDto, @Param('shopSlug') shopSlug: string) {
|
||||
// Only show approved reviews for public endpoint
|
||||
return this.reviewService.findRestuarantAllReviews({ ...dto, status: ReviewStatus.APPROVED, restuarantSlug });
|
||||
return this.reviewService.findRestuarantAllReviews({ ...dto, status: ReviewStatus.APPROVED, shopSlug });
|
||||
}
|
||||
|
||||
// @Get('public/reviews/:id')
|
||||
@@ -81,9 +68,6 @@ export class ReviewController {
|
||||
@Patch('public/reviews/:reviewId')
|
||||
@ApiOperation({ summary: 'Update a review (own reviews only)' })
|
||||
@ApiHeader(API_HEADER_SLUG)
|
||||
@ApiParam({ name: 'reviewId', required: true })
|
||||
@ApiBody({ type: UpdateReviewDto })
|
||||
@ApiOkResponse({ description: 'The updated review' })
|
||||
update(@Param('reviewId') reviewId: string, @Body() updateReviewDto: UpdateReviewDto, @UserId() userId: string) {
|
||||
return this.reviewService.update(reviewId, userId, updateReviewDto, false);
|
||||
}
|
||||
@@ -93,7 +77,6 @@ export class ReviewController {
|
||||
@Delete('public/reviews/:id')
|
||||
@ApiOperation({ summary: 'Delete a review (own reviews only)' })
|
||||
@ApiHeader(API_HEADER_SLUG)
|
||||
@ApiParam({ name: 'id', required: true })
|
||||
remove(@Param('id') id: string, @UserId() userId: string) {
|
||||
return this.reviewService.remove(id, userId, false);
|
||||
}
|
||||
@@ -105,25 +88,15 @@ export class ReviewController {
|
||||
@Permissions(Permission.MANAGE_REVIEWS)
|
||||
@Get('admin/reviews')
|
||||
@ApiOperation({ summary: 'Get all reviews (admin - including unapproved)' })
|
||||
@ApiOkResponse({ description: 'List of all reviews' })
|
||||
@ApiQuery({ name: 'page', required: false, type: Number })
|
||||
@ApiQuery({ name: 'limit', required: false, type: Number })
|
||||
@ApiQuery({ name: 'foodId', required: false, type: String })
|
||||
@ApiQuery({ name: 'userId', required: false, type: String })
|
||||
@ApiQuery({ name: 'status', required: false, enum: ReviewStatus })
|
||||
@ApiQuery({ name: 'orderBy', required: false, type: String })
|
||||
@ApiQuery({ name: 'order', required: false, enum: ['asc', 'desc'] })
|
||||
findAllAdmin(@Query() dto: FindReviewsDto, @ShopId() restId: string) {
|
||||
return this.reviewService.findAll({ ...dto, restId: restId });
|
||||
return this.reviewService.findAll({ ...dto, shopId: restId });
|
||||
}
|
||||
|
||||
@Patch('admin/reviews/:id')
|
||||
@UseGuards(AdminAuthGuard)
|
||||
@ApiBearerAuth()
|
||||
@Permissions(Permission.MANAGE_REVIEWS)
|
||||
@Patch('admin/reviews/:id')
|
||||
@ApiOperation({ summary: 'Update a review (admin - can change approval status)' })
|
||||
@ApiParam({ name: 'id', required: true })
|
||||
@ApiBody({ type: UpdateReviewDto })
|
||||
updateAdmin(@Param('id') id: string, @Body() updateReviewDto: UpdateReviewDto, @UserId() userId: string) {
|
||||
return this.reviewService.update(id, userId, updateReviewDto, true);
|
||||
}
|
||||
@@ -133,7 +106,6 @@ export class ReviewController {
|
||||
@Permissions(Permission.MANAGE_REVIEWS)
|
||||
@Get('admin/reviews/:id')
|
||||
@ApiOperation({ summary: 'review detail' })
|
||||
@ApiParam({ name: 'id', required: true })
|
||||
reviewDetail(@Param('id') reviewId: string, @ShopId() restaurantId: string) {
|
||||
return this.reviewService.findById(reviewId, restaurantId);
|
||||
}
|
||||
@@ -143,8 +115,6 @@ export class ReviewController {
|
||||
@Permissions(Permission.MANAGE_REVIEWS)
|
||||
@Patch('admin/reviews/:id/status')
|
||||
@ApiOperation({ summary: 'Change review status (pending, approved, rejected)' })
|
||||
@ApiParam({ name: 'id', required: true })
|
||||
@ApiBody({ type: ChangeStatusDto })
|
||||
changeStatus(
|
||||
@Param('id') reviewId: string,
|
||||
@Body() changeStatusDto: ChangeStatusDto,
|
||||
@@ -158,7 +128,6 @@ export class ReviewController {
|
||||
@ApiBearerAuth()
|
||||
@Delete('admin/reviews/:id')
|
||||
@ApiOperation({ summary: 'Delete a review (admin)' })
|
||||
@ApiParam({ name: 'id', required: true })
|
||||
removeAdmin(@Param('id') id: string, @UserId() userId: string) {
|
||||
return this.reviewService.remove(id, userId, true);
|
||||
}
|
||||
|
||||
@@ -19,12 +19,12 @@ export class FindReviewsDto {
|
||||
@IsOptional()
|
||||
@IsString()
|
||||
@ApiPropertyOptional({ description: 'Product ID to filter comments' })
|
||||
foodId?: string;
|
||||
productId?: string;
|
||||
|
||||
@IsOptional()
|
||||
@IsString()
|
||||
@ApiPropertyOptional({ description: 'Shop ID to filter comments' })
|
||||
restId?: string;
|
||||
shopId?: string;
|
||||
|
||||
@IsOptional()
|
||||
@IsString()
|
||||
@@ -51,5 +51,5 @@ export class FindRestuarantReviewsDto extends FindReviewsDto {
|
||||
@IsOptional()
|
||||
@IsString()
|
||||
@ApiPropertyOptional({ description: 'Shop slug to filter comments' })
|
||||
restuarantSlug?: string;
|
||||
shopSlug?: string;
|
||||
}
|
||||
|
||||
@@ -112,7 +112,7 @@ export class ReviewService {
|
||||
}
|
||||
|
||||
async findRestuarantAllReviews(dto: FindRestuarantReviewsDto) {
|
||||
const { restuarantSlug, ...restDto } = dto;
|
||||
const { shopSlug: restuarantSlug, ...restDto } = dto;
|
||||
const shop = await this.em.findOne(Shop, { slug: restuarantSlug });
|
||||
if (!shop) {
|
||||
throw new NotFoundException('RestaurantMessage.NOT_FOUND');
|
||||
|
||||
Reference in New Issue
Block a user