update
This commit is contained in:
@@ -489,7 +489,7 @@ export class CartService {
|
|||||||
*/
|
*/
|
||||||
async setAddress(userId: string, restaurantId: string, setAddressDto: SetAddressDto): Promise<Cart> {
|
async setAddress(userId: string, restaurantId: string, setAddressDto: SetAddressDto): Promise<Cart> {
|
||||||
const cart = await this.findOneOrFail(userId, restaurantId);
|
const cart = await this.findOneOrFail(userId, restaurantId);
|
||||||
|
|
||||||
if (!cart.deliveryMethodId) throw new BadRequestException('Delivery method must be set before setting address');
|
if (!cart.deliveryMethodId) throw new BadRequestException('Delivery method must be set before setting address');
|
||||||
// Find and validate address belongs to user
|
// Find and validate address belongs to user
|
||||||
const address = await this.em.findOne(UserAddress, { id: setAddressDto.addressId }, { populate: ['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 { BaseEntity } from '../../../common/entities/base.entity';
|
||||||
import { Food } from '../../foods/entities/food.entity';
|
import { Food } from '../../foods/entities/food.entity';
|
||||||
import { User } from '../../users/entities/user.entity';
|
import { User } from '../../users/entities/user.entity';
|
||||||
|
import { Order } from 'src/modules/orders/entities/order.entity';
|
||||||
|
|
||||||
@Entity({ tableName: 'food_comments' })
|
@Entity({ tableName: 'food_comments' })
|
||||||
|
@Unique({ properties: ['order', 'food', 'user'] })
|
||||||
export class FoodComment extends BaseEntity {
|
export class FoodComment extends BaseEntity {
|
||||||
|
@ManyToOne(() => Order)
|
||||||
|
order: Order;
|
||||||
|
|
||||||
@ManyToOne(() => Food)
|
@ManyToOne(() => Food)
|
||||||
food!: Food;
|
food: Food;
|
||||||
|
|
||||||
@ManyToOne(() => User)
|
@ManyToOne(() => User)
|
||||||
user!: User;
|
user: User;
|
||||||
|
|
||||||
@Property({ type: 'text', nullable: true })
|
@Property({ type: 'text', nullable: true })
|
||||||
comment?: string;
|
comment?: string;
|
||||||
|
|
||||||
@Property({ type: 'int', nullable: false })
|
@Property({ type: 'int', nullable: false })
|
||||||
rating!: number; // 1-5
|
rating: number = 0;
|
||||||
|
|
||||||
@Property({ type: 'boolean', default: false })
|
@Property({ type: 'boolean', default: false })
|
||||||
isApproved: boolean = false;
|
isApproved: boolean = false;
|
||||||
|
|||||||
@@ -68,7 +68,7 @@ export class FoodCommentService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async findById(id: string): Promise<FoodComment> {
|
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) {
|
if (!comment) {
|
||||||
throw new NotFoundException(FoodCommentMessage.NOT_FOUND);
|
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> {
|
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) {
|
if (!comment) {
|
||||||
throw new NotFoundException(FoodCommentMessage.NOT_FOUND);
|
throw new NotFoundException(FoodCommentMessage.NOT_FOUND);
|
||||||
}
|
}
|
||||||
@@ -104,7 +104,7 @@ export class FoodCommentService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async remove(id: string, userId: string, isAdmin: boolean = false) {
|
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) {
|
if (!comment) {
|
||||||
throw new NotFoundException(FoodCommentMessage.NOT_FOUND);
|
throw new NotFoundException(FoodCommentMessage.NOT_FOUND);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -47,7 +47,7 @@ export class FoodCommentRepository extends EntityRepository<FoodComment> {
|
|||||||
limit,
|
limit,
|
||||||
offset,
|
offset,
|
||||||
orderBy: { [orderBy]: order.toLowerCase() as 'asc' | 'desc' },
|
orderBy: { [orderBy]: order.toLowerCase() as 'asc' | 'desc' },
|
||||||
populate: ['food', 'user'],
|
populate: ['food', 'user', 'order'],
|
||||||
});
|
});
|
||||||
|
|
||||||
const totalPages = Math.ceil(total / limit);
|
const totalPages = Math.ceil(total / limit);
|
||||||
|
|||||||
Reference in New Issue
Block a user