status
This commit is contained in:
@@ -19,6 +19,7 @@ export enum OrderStatus {
|
|||||||
ReadyForDeliveryCar = 'readyForDeliveryCar',
|
ReadyForDeliveryCar = 'readyForDeliveryCar',
|
||||||
ReadyForDeliveryCourier = 'readyForDeliveryCourier',
|
ReadyForDeliveryCourier = 'readyForDeliveryCourier',
|
||||||
|
|
||||||
|
Shipping = 'shipping',
|
||||||
// Final status
|
// Final status
|
||||||
Delivered = 'delivered',
|
Delivered = 'delivered',
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -90,21 +90,42 @@ export class OrdersController {
|
|||||||
return this.ordersService.rejectOrder(orderId, restId);
|
return this.ordersService.rejectOrder(orderId, restId);
|
||||||
}
|
}
|
||||||
|
|
||||||
@UseGuards(AdminAuthGuard)
|
// @UseGuards(AdminAuthGuard)
|
||||||
@ApiBearerAuth()
|
// @ApiBearerAuth()
|
||||||
@Patch('admin/orders/:orderId/ready')
|
// @Patch('admin/orders/:orderId/ready')
|
||||||
@ApiOperation({ summary: 'Ready for pickup or delivery ' })
|
// @ApiOperation({ summary: 'Ready for pickup or delivery ' })
|
||||||
@ApiParam({ name: 'orderId', description: 'Order ID' })
|
// @ApiParam({ name: 'orderId', description: 'Order ID' })
|
||||||
readyForPickup(@Param('orderId') orderId: string, @RestId() restId: string) {
|
// readyForPickup(@Param('orderId') orderId: string, @RestId() restId: string) {
|
||||||
return this.ordersService.readyForDelivery(orderId, restId);
|
// return this.ordersService.readyForDelivery(orderId, restId);
|
||||||
}
|
// }
|
||||||
|
|
||||||
|
// @UseGuards(AdminAuthGuard)
|
||||||
|
// @ApiBearerAuth()
|
||||||
|
// @Patch('admin/orders/:orderId/delivered')
|
||||||
|
// @ApiOperation({ summary: 'Mark an order as delivered' })
|
||||||
|
// @ApiParam({ name: 'orderId', description: 'Order ID' })
|
||||||
|
// markAsDelivered(@Param('orderId') orderId: string, @RestId() restId: string) {
|
||||||
|
// return this.ordersService.markAsDelivered(orderId, restId);
|
||||||
|
// }
|
||||||
|
|
||||||
@UseGuards(AdminAuthGuard)
|
@UseGuards(AdminAuthGuard)
|
||||||
@ApiBearerAuth()
|
@ApiBearerAuth()
|
||||||
@Patch('admin/orders/:orderId/delivered')
|
@Patch('admin/orders/:orderId/:status')
|
||||||
@ApiOperation({ summary: 'Mark an order as delivered' })
|
@ApiOperation({ summary: 'Update an order status' })
|
||||||
@ApiParam({ name: 'orderId', description: 'Order ID' })
|
@ApiParam({ name: 'orderId', description: 'Order ID' })
|
||||||
markAsDelivered(@Param('orderId') orderId: string, @RestId() restId: string) {
|
@ApiParam({
|
||||||
return this.ordersService.markAsDelivered(orderId, restId);
|
name: 'status',
|
||||||
|
description: 'Order status',
|
||||||
|
enum: [
|
||||||
|
'readyForCustomerPickup',
|
||||||
|
'readyForDineIn',
|
||||||
|
'readyForDeliveryCar',
|
||||||
|
'readyForDeliveryCourier',
|
||||||
|
'shipping',
|
||||||
|
'delivered',
|
||||||
|
],
|
||||||
|
})
|
||||||
|
updateStatus(@Param('orderId') orderId: string, @Param('status') status: string, @RestId() restId: string) {
|
||||||
|
return this.ordersService.updateStatus(orderId, status, restId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ import { Food } from '../foods/entities/food.entity';
|
|||||||
import { UserAddress } from '../users/entities/user-address.entity';
|
import { UserAddress } from '../users/entities/user-address.entity';
|
||||||
import { CartService } from '../cart/providers/cart.service';
|
import { CartService } from '../cart/providers/cart.service';
|
||||||
import { OrderStatus } from './interface/order-status';
|
import { OrderStatus } from './interface/order-status';
|
||||||
import { PaymentStatusEnum } from '../payments/interface/payment';
|
import { PaymentMethodEnum, PaymentStatusEnum } from '../payments/interface/payment';
|
||||||
import { Cart } from '../cart/interfaces/cart.interface';
|
import { Cart } from '../cart/interfaces/cart.interface';
|
||||||
import { PaymentMethod } from '../payments/entities/payment-method.entity';
|
import { PaymentMethod } from '../payments/entities/payment-method.entity';
|
||||||
// import { PaymentGatewayService } from '../payments/services/payment-gateway.service.tss';
|
// import { PaymentGatewayService } from '../payments/services/payment-gateway.service.tss';
|
||||||
@@ -277,6 +277,12 @@ export class OrdersService {
|
|||||||
if (!order) {
|
if (!order) {
|
||||||
throw new NotFoundException('Order not found');
|
throw new NotFoundException('Order not found');
|
||||||
}
|
}
|
||||||
|
if (order.status !== OrderStatus.Pending) {
|
||||||
|
throw new BadRequestException('Order must be pending before accepting');
|
||||||
|
}
|
||||||
|
if (order.paymentMethod?.method === PaymentMethodEnum.Online && order.paymentStatus !== PaymentStatusEnum.Paid) {
|
||||||
|
throw new BadRequestException('Order must be paid online before accepting');
|
||||||
|
}
|
||||||
order.status = OrderStatus.Confirmed;
|
order.status = OrderStatus.Confirmed;
|
||||||
await this.em.persistAndFlush(order);
|
await this.em.persistAndFlush(order);
|
||||||
return order;
|
return order;
|
||||||
@@ -371,6 +377,39 @@ export class OrdersService {
|
|||||||
return order;
|
return order;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async updateStatus(orderId: string, status: string, restId: string) {
|
||||||
|
const order = await this.em.findOne(Order, { id: orderId, restaurant: { id: restId } });
|
||||||
|
if (!order) {
|
||||||
|
throw new NotFoundException('Order not found');
|
||||||
|
}
|
||||||
|
|
||||||
|
// Map string status to OrderStatus enum
|
||||||
|
const statusMap: Record<string, OrderStatus> = {
|
||||||
|
ReadyForCustomerPickup: OrderStatus.ReadyForCustomerPickup,
|
||||||
|
readyForCustomerPickup: OrderStatus.ReadyForCustomerPickup,
|
||||||
|
ReadyForDineIn: OrderStatus.ReadyForDineIn,
|
||||||
|
readyForDineIn: OrderStatus.ReadyForDineIn,
|
||||||
|
ReadyForDeliveryCar: OrderStatus.ReadyForDeliveryCar,
|
||||||
|
readyForDeliveryCar: OrderStatus.ReadyForDeliveryCar,
|
||||||
|
ReadyForDeliveryCourier: OrderStatus.ReadyForDeliveryCourier,
|
||||||
|
readyForDeliveryCourier: OrderStatus.ReadyForDeliveryCourier,
|
||||||
|
shipping: OrderStatus.Shipping,
|
||||||
|
Delivered: OrderStatus.Delivered,
|
||||||
|
delivered: OrderStatus.Delivered,
|
||||||
|
};
|
||||||
|
|
||||||
|
const newStatus = statusMap[status];
|
||||||
|
if (!newStatus) {
|
||||||
|
throw new BadRequestException(
|
||||||
|
`Invalid status: ${status}. Allowed statuses: shipping, Delivered, ReadyForCustomerPickup, ReadyForDineIn, ReadyForDeliveryCar, ReadyForDeliveryCourier`,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
order.status = newStatus;
|
||||||
|
await this.em.persistAndFlush(order);
|
||||||
|
return order;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Cleanup job to handle abandoned orders (pending payment for >30 minutes)
|
* Cleanup job to handle abandoned orders (pending payment for >30 minutes)
|
||||||
* Runs every 10 minutes to check for abandoned orders
|
* Runs every 10 minutes to check for abandoned orders
|
||||||
|
|||||||
Reference in New Issue
Block a user