This commit is contained in:
2025-12-06 11:00:25 +03:30
parent 297e23e164
commit 69e27aa7f6
2 changed files with 39 additions and 20 deletions
+20 -10
View File
@@ -252,9 +252,9 @@ export class OrdersService {
});
}
async findOne(id: string): Promise<Order> {
async findOne(id: string, restId: string): Promise<Order> {
const order = await this.orderRepository.findOne(
{ id },
{ id, restaurant: { id: restId } },
{ populate: ['user', 'restaurant', 'deliveryMethod', 'address', 'paymentMethod', 'items', 'items.food'] },
);
if (!order) {
@@ -263,8 +263,8 @@ export class OrdersService {
return order;
}
async acceptOrder(orderId: string) {
const order = await this.em.findOne(Order, { id: orderId });
async acceptOrder(orderId: string, restId: string) {
const order = await this.em.findOne(Order, { id: orderId, restaurant: { id: restId } });
if (!order) {
throw new NotFoundException('Order not found');
}
@@ -273,8 +273,18 @@ export class OrdersService {
return order;
}
async rejectOrder(orderId: string) {
const order = await this.em.findOne(Order, { id: orderId });
async prepareOrder(orderId: string, restId: string) {
const order = await this.em.findOne(Order, { id: orderId, restaurant: { id: restId } });
if (!order) {
throw new NotFoundException('Order not found');
}
order.status = OrderStatus.Confirmed;
await this.em.persistAndFlush(order);
return order;
}
async rejectOrder(orderId: string, restId: string) {
const order = await this.em.findOne(Order, { id: orderId, restaurant: { id: restId } });
if (!order) {
throw new NotFoundException('Order not found');
}
@@ -283,8 +293,8 @@ export class OrdersService {
return order;
}
async readyForDelivery(orderId: string) {
const order = await this.em.findOne(Order, { id: orderId });
async readyForDelivery(orderId: string, restId: string) {
const order = await this.em.findOne(Order, { id: orderId, restaurant: { id: restId } });
if (!order) {
throw new NotFoundException('Order not found');
}
@@ -312,8 +322,8 @@ export class OrdersService {
return order;
}
async cancelOrder(orderId: string) {
const order = await this.em.findOne(Order, { id: orderId });
async cancelOrder(orderId: string, restId: string) {
const order = await this.em.findOne(Order, { id: orderId, restaurant: { id: restId } });
if (!order) {
throw new NotFoundException('Order not found');
}