update
This commit is contained in:
@@ -1,21 +1,26 @@
|
||||
import { Entity, ManyToOne, Property } from '@mikro-orm/core';
|
||||
import { Entity, ManyToOne, Property, Unique } from '@mikro-orm/core';
|
||||
import { BaseEntity } from '../../../common/entities/base.entity';
|
||||
import { Food } from '../../foods/entities/food.entity';
|
||||
import { User } from '../../users/entities/user.entity';
|
||||
import { Order } from 'src/modules/orders/entities/order.entity';
|
||||
|
||||
@Entity({ tableName: 'food_comments' })
|
||||
@Unique({ properties: ['order', 'food', 'user'] })
|
||||
export class FoodComment extends BaseEntity {
|
||||
@ManyToOne(() => Order)
|
||||
order: Order;
|
||||
|
||||
@ManyToOne(() => Food)
|
||||
food!: Food;
|
||||
food: Food;
|
||||
|
||||
@ManyToOne(() => User)
|
||||
user!: User;
|
||||
user: User;
|
||||
|
||||
@Property({ type: 'text', nullable: true })
|
||||
comment?: string;
|
||||
|
||||
@Property({ type: 'int', nullable: false })
|
||||
rating!: number; // 1-5
|
||||
rating: number = 0;
|
||||
|
||||
@Property({ type: 'boolean', default: false })
|
||||
isApproved: boolean = false;
|
||||
|
||||
@@ -68,7 +68,7 @@ export class FoodCommentService {
|
||||
}
|
||||
|
||||
async findById(id: string): Promise<FoodComment> {
|
||||
const comment = await this.foodCommentRepository.findOne({ id }, { populate: ['food', 'user'] });
|
||||
const comment = await this.foodCommentRepository.findOne({ id }, { populate: ['food', 'user', 'order'] });
|
||||
if (!comment) {
|
||||
throw new NotFoundException(FoodCommentMessage.NOT_FOUND);
|
||||
}
|
||||
@@ -76,7 +76,7 @@ export class FoodCommentService {
|
||||
}
|
||||
|
||||
async update(id: string, userId: string, dto: UpdateFoodCommentDto, isAdmin: boolean = false): Promise<FoodComment> {
|
||||
const comment = await this.foodCommentRepository.findOne({ id }, { populate: ['food', 'user'] });
|
||||
const comment = await this.foodCommentRepository.findOne({ id }, { populate: ['food', 'user', 'order'] });
|
||||
if (!comment) {
|
||||
throw new NotFoundException(FoodCommentMessage.NOT_FOUND);
|
||||
}
|
||||
@@ -104,7 +104,7 @@ export class FoodCommentService {
|
||||
}
|
||||
|
||||
async remove(id: string, userId: string, isAdmin: boolean = false) {
|
||||
const comment = await this.foodCommentRepository.findOne({ id }, { populate: ['food', 'user'] });
|
||||
const comment = await this.foodCommentRepository.findOne({ id }, { populate: ['food', 'user', 'order'] });
|
||||
if (!comment) {
|
||||
throw new NotFoundException(FoodCommentMessage.NOT_FOUND);
|
||||
}
|
||||
|
||||
@@ -47,7 +47,7 @@ export class FoodCommentRepository extends EntityRepository<FoodComment> {
|
||||
limit,
|
||||
offset,
|
||||
orderBy: { [orderBy]: order.toLowerCase() as 'asc' | 'desc' },
|
||||
populate: ['food', 'user'],
|
||||
populate: ['food', 'user', 'order'],
|
||||
});
|
||||
|
||||
const totalPages = Math.ceil(total / limit);
|
||||
|
||||
Reference in New Issue
Block a user