This commit is contained in:
2025-12-07 10:26:09 +03:30
parent be0185e6bd
commit f762b03260
4 changed files with 14 additions and 9 deletions
+1 -1
View File
@@ -489,7 +489,7 @@ export class CartService {
*/
async setAddress(userId: string, restaurantId: string, setAddressDto: SetAddressDto): Promise<Cart> {
const cart = await this.findOneOrFail(userId, restaurantId);
if (!cart.deliveryMethodId) throw new BadRequestException('Delivery method must be set before setting address');
// Find and validate address belongs to user
const address = await this.em.findOne(UserAddress, { id: setAddressDto.addressId }, { populate: ['user'] });
@@ -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);