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