orders
This commit is contained in:
@@ -250,9 +250,53 @@ export class OrdersService {
|
||||
return `This action returns a #${id} order`;
|
||||
}
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
update(id: number, _updateOrderDto: unknown) {
|
||||
return `This action updates a #${id} order`;
|
||||
async acceptOrder(orderId: string) {
|
||||
const order = await this.em.findOne(Order, { id: orderId });
|
||||
if (!order) {
|
||||
throw new NotFoundException('Order not found');
|
||||
}
|
||||
order.status = OrderStatus.Confirmed;
|
||||
await this.em.persistAndFlush(order);
|
||||
return order;
|
||||
}
|
||||
|
||||
async rejectOrder(orderId: string) {
|
||||
const order = await this.em.findOne(Order, { id: orderId });
|
||||
if (!order) {
|
||||
throw new NotFoundException('Order not found');
|
||||
}
|
||||
order.status = OrderStatus.RejectedByRestaurant;
|
||||
await this.em.persistAndFlush(order);
|
||||
return order;
|
||||
}
|
||||
|
||||
async readyForDelivery(orderId: string) {
|
||||
const order = await this.em.findOne(Order, { id: orderId });
|
||||
if (!order) {
|
||||
throw new NotFoundException('Order not found');
|
||||
}
|
||||
let orderStatus: OrderStatus | undefined;
|
||||
|
||||
switch (order.deliveryMethod.method) {
|
||||
case DeliveryMethodEnum.DeliveryCourier:
|
||||
orderStatus = OrderStatus.ReadyForDeliveryCourier;
|
||||
break;
|
||||
case DeliveryMethodEnum.DeliveryCar:
|
||||
orderStatus = OrderStatus.ReadyForDeliveryCar;
|
||||
break;
|
||||
case DeliveryMethodEnum.DineIn:
|
||||
orderStatus = OrderStatus.ReadyForDineIn;
|
||||
break;
|
||||
case DeliveryMethodEnum.CustomerPickup:
|
||||
orderStatus = OrderStatus.ReadyForCustomerPickup;
|
||||
break;
|
||||
default:
|
||||
throw new BadRequestException('Invalid delivery method');
|
||||
}
|
||||
|
||||
order.status = orderStatus;
|
||||
await this.em.persistAndFlush(order);
|
||||
return order;
|
||||
}
|
||||
|
||||
remove(id: number) {
|
||||
@@ -307,7 +351,7 @@ export class OrdersService {
|
||||
}
|
||||
|
||||
// Update order status to Cancelled
|
||||
order.status = OrderStatus.Cancelled;
|
||||
order.status = OrderStatus.CancelledBySystem;
|
||||
em.persist(order);
|
||||
|
||||
await em.flush();
|
||||
|
||||
Reference in New Issue
Block a user