rewview
This commit is contained in:
@@ -2,7 +2,7 @@ import { Controller, Get, Post, Body, Patch, Param, Delete, Query, UseGuards } f
|
||||
import { ReviewService } from '../providers/review.service';
|
||||
import { CreateReviewDto } from '../dto/create-review.dto';
|
||||
import { UpdateReviewDto } from '../dto/update-review.dto';
|
||||
import { FindReviewsDto } from '../dto/find-reviews.dto';
|
||||
import { FindReviewsDto, FindRestuarantReviewsDto } from '../dto/find-reviews.dto';
|
||||
import {
|
||||
ApiTags,
|
||||
ApiOperation,
|
||||
@@ -35,11 +35,11 @@ export class ReviewController {
|
||||
}
|
||||
|
||||
@Get('public/reviews/:foodId')
|
||||
@ApiOperation({ summary: 'Get all reviews (public - only approved)' })
|
||||
@ApiOperation({ summary: 'Get all reviews of food by id(public - only approved)' })
|
||||
@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 })
|
||||
@ApiParam({ name: 'foodId', required: true, type: String })
|
||||
@ApiQuery({ name: 'orderBy', required: false, type: String })
|
||||
@ApiQuery({ name: 'order', required: false, enum: ['asc', 'desc'] })
|
||||
findAll(@Query() dto: FindReviewsDto, @Param('foodId') foodId: string) {
|
||||
@@ -47,6 +47,19 @@ export class ReviewController {
|
||||
return this.reviewService.findAll({ ...dto, isApproved: true, foodId });
|
||||
}
|
||||
|
||||
@Get('public/reviews/restuarant/:restuarantSlug')
|
||||
@ApiOperation({ summary: 'Get all reviews of restuarant by slug(public - only approved)' })
|
||||
@ApiOkResponse({ description: 'List of approved reviews' })
|
||||
@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) {
|
||||
// Only show approved reviews for public endpoint
|
||||
return this.reviewService.findRestuarantAllReviews({ ...dto, isApproved: true });
|
||||
}
|
||||
|
||||
// @Get('public/reviews/:id')
|
||||
// @ApiOperation({ summary: 'Get a review by id' })
|
||||
// @ApiParam({ name: 'id', required: true })
|
||||
|
||||
@@ -47,3 +47,9 @@ export class FindReviewsDto {
|
||||
order?: 'asc' | 'desc';
|
||||
}
|
||||
|
||||
export class FindRestuarantReviewsDto extends FindReviewsDto {
|
||||
@IsOptional()
|
||||
@IsString()
|
||||
@ApiPropertyOptional({ description: 'Restaurant slug to filter comments' })
|
||||
restuarantSlug?: string;
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { Injectable, NotFoundException, BadRequestException } from '@nestjs/common';
|
||||
import { CreateReviewDto } from '../dto/create-review.dto';
|
||||
import { UpdateReviewDto } from '../dto/update-review.dto';
|
||||
import { FindReviewsDto } from '../dto/find-reviews.dto';
|
||||
import { FindRestuarantReviewsDto, FindReviewsDto } from '../dto/find-reviews.dto';
|
||||
import { ReviewRepository } from '../repositories/review.repository';
|
||||
import { FoodRepository } from '../../foods/repositories/food.repository';
|
||||
import { UserRepository } from '../../users/repositories/user.repository';
|
||||
@@ -11,6 +11,7 @@ import { Review } from '../entities/review.entity';
|
||||
import { FoodMessage, UserMessage, ReviewMessage } from 'src/common/enums/message.enum';
|
||||
import { Order } from '../../orders/entities/order.entity';
|
||||
import { OrderItem } from '../../orders/entities/order-item.entity';
|
||||
import { Restaurant } from 'src/modules/restaurants/entities/restaurant.entity';
|
||||
|
||||
@Injectable()
|
||||
export class ReviewService {
|
||||
@@ -88,6 +89,15 @@ export class ReviewService {
|
||||
return this.reviewRepository.findAllPaginated(dto);
|
||||
}
|
||||
|
||||
async findRestuarantAllReviews(dto: FindRestuarantReviewsDto) {
|
||||
const { restuarantSlug, ...restDto } = dto;
|
||||
const restaurant = await this.em.findOne(Restaurant, { slug: restuarantSlug });
|
||||
if (!restaurant) {
|
||||
throw new NotFoundException('RestaurantMessage.NOT_FOUND');
|
||||
}
|
||||
return this.reviewRepository.findAllPaginated({ ...restDto, restId: restaurant.id });
|
||||
}
|
||||
|
||||
async findById(id: string): Promise<Review> {
|
||||
const review = await this.reviewRepository.findOne({ id }, { populate: ['food', 'user', 'order'] });
|
||||
if (!review) {
|
||||
@@ -167,4 +177,3 @@ export class ReviewService {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -11,6 +11,7 @@ type FindReviewsOpts = {
|
||||
userId?: string;
|
||||
isApproved?: boolean;
|
||||
orderBy?: string;
|
||||
restId?: string;
|
||||
order?: 'asc' | 'desc';
|
||||
};
|
||||
|
||||
@@ -25,7 +26,7 @@ export class ReviewRepository extends EntityRepository<Review> {
|
||||
* Supports: foodId, userId, isApproved, ordering.
|
||||
*/
|
||||
async findAllPaginated(opts: FindReviewsOpts = {}): Promise<PaginatedResult<Review>> {
|
||||
const { page = 1, limit = 10, foodId, userId, isApproved, orderBy = 'createdAt', order = 'desc' } = opts;
|
||||
const { page = 1, limit = 10, foodId, restId, userId, isApproved, orderBy = 'createdAt', order = 'desc' } = opts;
|
||||
|
||||
const offset = (page - 1) * limit;
|
||||
|
||||
@@ -35,6 +36,10 @@ export class ReviewRepository extends EntityRepository<Review> {
|
||||
where.food = { id: foodId };
|
||||
}
|
||||
|
||||
if (restId) {
|
||||
where.food = { restaurant: { id: restId } };
|
||||
}
|
||||
|
||||
if (userId) {
|
||||
where.user = { id: userId };
|
||||
}
|
||||
@@ -63,4 +68,3 @@ export class ReviewRepository extends EntityRepository<Review> {
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user