update order status
This commit is contained in:
@@ -47,8 +47,7 @@ export class OrdersService {
|
||||
private readonly logger = new Logger(OrdersService.name);
|
||||
|
||||
private static readonly STATUS_TRANSITIONS: Record<OrderStatus, readonly OrderStatus[]> = {
|
||||
[OrderStatus.PENDING_PAYMENT]: [OrderStatus.PAID, OrderStatus.CANCELED, OrderStatus.PREPARING],
|
||||
[OrderStatus.PAID]: [OrderStatus.PREPARING, OrderStatus.CANCELED],
|
||||
[OrderStatus.NEW]: [ OrderStatus.CANCELED, OrderStatus.PREPARING],
|
||||
[OrderStatus.PREPARING]: [OrderStatus.DELIVERED_TO_RECEPTIONIST, OrderStatus.DELIVERED_TO_WAITER, OrderStatus.SHIPPED, OrderStatus.CANCELED],
|
||||
[OrderStatus.DELIVERED_TO_WAITER]: [OrderStatus.COMPLETED, OrderStatus.CANCELED],
|
||||
[OrderStatus.DELIVERED_TO_RECEPTIONIST]: [OrderStatus.COMPLETED, OrderStatus.CANCELED],
|
||||
@@ -92,8 +91,8 @@ export class OrdersService {
|
||||
description: cart.description,
|
||||
printInvoice: cart.printInvoice ?? false,
|
||||
tableNumber: cart.tableNumber,
|
||||
status: OrderStatus.PENDING_PAYMENT,
|
||||
history: [{ status: OrderStatus.PENDING_PAYMENT, changedAt: new Date() }],
|
||||
status: OrderStatus.NEW,
|
||||
history: [{ status: OrderStatus.NEW, changedAt: new Date() }],
|
||||
});
|
||||
|
||||
em.persist(order);
|
||||
@@ -206,8 +205,8 @@ export class OrdersService {
|
||||
description: dto.description,
|
||||
printInvoice: false,
|
||||
tableNumber: dto.tableNumber,
|
||||
status: OrderStatus.PENDING_PAYMENT,
|
||||
history: [{ status: OrderStatus.PENDING_PAYMENT, changedAt: new Date() }],
|
||||
status: OrderStatus.NEW,
|
||||
history: [{ status: OrderStatus.NEW, changedAt: new Date() }],
|
||||
});
|
||||
|
||||
em.persist(order);
|
||||
@@ -431,8 +430,8 @@ export class OrdersService {
|
||||
if (!OrdersService.STATUS_TRANSITIONS[from]?.includes(to)) return false;
|
||||
|
||||
if (to === OrderStatus.CANCELED) {
|
||||
// only allow orders with status of PENDING_PAYMENT and PAID are allowed to be canceled by user
|
||||
if (ref === 'user' && ![OrderStatus.PENDING_PAYMENT, OrderStatus.PAID].includes(from)) {
|
||||
// only allow orders with status of NEW are allowed to be canceled by user
|
||||
if (ref === 'user' && ![OrderStatus.NEW].includes(from)) {
|
||||
return false;
|
||||
} else if (ref === 'admin') {
|
||||
return true;
|
||||
@@ -441,7 +440,7 @@ export class OrdersService {
|
||||
// only allow orders with status of PENDING_PAYMENT and payment
|
||||
// method of cash are allowed to move to CONFIRMED directly
|
||||
if (
|
||||
from == OrderStatus.PENDING_PAYMENT &&
|
||||
from == OrderStatus.NEW &&
|
||||
to == OrderStatus.PREPARING &&
|
||||
paymentMethod !== PaymentMethodEnum.Cash &&
|
||||
paymentMethod !== PaymentMethodEnum.CreditCard
|
||||
@@ -475,10 +474,6 @@ export class OrdersService {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (paymentMethod === PaymentMethodEnum.Online) {
|
||||
if (to === OrderStatus.PREPARING && from !== OrderStatus.PAID) return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -709,7 +704,6 @@ export class OrdersService {
|
||||
restaurant: { id: restId },
|
||||
status: {
|
||||
$in: [
|
||||
OrderStatus.PAID,
|
||||
OrderStatus.PREPARING,
|
||||
OrderStatus.DELIVERED_TO_WAITER,
|
||||
OrderStatus.DELIVERED_TO_RECEPTIONIST,
|
||||
|
||||
Reference in New Issue
Block a user