fix bugs in order
This commit is contained in:
@@ -96,6 +96,7 @@ export class OrdersCrone {
|
||||
status: {
|
||||
$in: [
|
||||
OrderStatus.SHIPPED,
|
||||
OrderStatus.DELIVERED_TO_RECEPIENT,
|
||||
],
|
||||
},
|
||||
updatedAt: { $lte: cutoff },
|
||||
|
||||
@@ -16,7 +16,7 @@ export enum OrderStatus {
|
||||
PENDING_PAYMENT = 'pendingPayment',
|
||||
PAID = 'paid',
|
||||
PREPARING = 'preparing',
|
||||
DELIVERED = 'delivered',
|
||||
DELIVERED_TO_RECEPIENT = 'deliveredToRecepient',
|
||||
SHIPPED = 'shipped',
|
||||
COMPLETED = 'completed',
|
||||
CANCELED = 'canceled',
|
||||
|
||||
@@ -35,7 +35,7 @@ export class OrderListeners {
|
||||
[OrderStatus.PENDING_PAYMENT]: 'در انتظار پرداخت',
|
||||
[OrderStatus.PAID]: 'پرداخت شده',
|
||||
[OrderStatus.PREPARING]: 'در حال آمادهسازی',
|
||||
[OrderStatus.DELIVERED]: 'تحویل شده',
|
||||
[OrderStatus.DELIVERED_TO_RECEPIENT]: 'تحویل به پیشخوان',
|
||||
[OrderStatus.SHIPPED]: 'ارسال شده',
|
||||
[OrderStatus.COMPLETED]: 'تکمیل شده',
|
||||
[OrderStatus.CANCELED]: 'لغو شده',
|
||||
|
||||
@@ -44,8 +44,8 @@ export class OrdersService {
|
||||
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.PREPARING]: [OrderStatus.DELIVERED, OrderStatus.SHIPPED, OrderStatus.CANCELED],
|
||||
[OrderStatus.DELIVERED]: [OrderStatus.COMPLETED, OrderStatus.CANCELED],
|
||||
[OrderStatus.PREPARING]: [OrderStatus.SHIPPED, OrderStatus.DELIVERED_TO_RECEPIENT, OrderStatus.CANCELED],
|
||||
[OrderStatus.DELIVERED_TO_RECEPIENT]: [OrderStatus.COMPLETED, OrderStatus.CANCELED],
|
||||
[OrderStatus.SHIPPED]: [OrderStatus.COMPLETED, OrderStatus.CANCELED],
|
||||
[OrderStatus.COMPLETED]: [OrderStatus.CANCELED],
|
||||
[OrderStatus.CANCELED]: [],
|
||||
@@ -244,8 +244,8 @@ export class OrdersService {
|
||||
OrderStatusChangedEvent.name,
|
||||
new OrderStatusChangedEvent(
|
||||
orderId,
|
||||
order.user?.id || '',
|
||||
String(order?.orderNumber) || '',
|
||||
order.user.id,
|
||||
String(order.orderNumber),
|
||||
shopId,
|
||||
previousStatus,
|
||||
toStatus,
|
||||
@@ -297,14 +297,6 @@ export class OrdersService {
|
||||
) {
|
||||
return false;
|
||||
}
|
||||
if (
|
||||
from == OrderStatus.PREPARING &&
|
||||
to == OrderStatus.DELIVERED &&
|
||||
deliveryMethod !== DeliveryMethodEnum.DeliveryCourier &&
|
||||
deliveryMethod !== DeliveryMethodEnum.CustomerPickup
|
||||
) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (paymentMethod === PaymentMethodEnum.Online) {
|
||||
if (to === OrderStatus.PREPARING && from !== OrderStatus.PAID) return false;
|
||||
@@ -393,7 +385,7 @@ export class OrdersService {
|
||||
$in: [
|
||||
OrderStatus.PAID,
|
||||
OrderStatus.PREPARING,
|
||||
OrderStatus.DELIVERED,
|
||||
OrderStatus.DELIVERED_TO_RECEPIENT,
|
||||
OrderStatus.SHIPPED,
|
||||
OrderStatus.COMPLETED,
|
||||
],
|
||||
@@ -411,7 +403,7 @@ export class OrdersService {
|
||||
`
|
||||
SELECT COUNT(DISTINCT o.user_id) as count
|
||||
FROM orders o
|
||||
WHERE o.restaurant_id = ?
|
||||
WHERE o.shop_id = ?
|
||||
`,
|
||||
[shopId],
|
||||
);
|
||||
@@ -423,7 +415,7 @@ export class OrdersService {
|
||||
SELECT COALESCE(SUM(p.amount), 0)::numeric as total
|
||||
FROM payments p
|
||||
INNER JOIN orders o ON p.order_id = o.id
|
||||
WHERE o.restaurant_id = ? AND p.status = 'paid'
|
||||
WHERE o.shop_id = ? AND p.status = 'paid'
|
||||
`,
|
||||
[shopId],
|
||||
);
|
||||
@@ -467,7 +459,7 @@ export class OrdersService {
|
||||
COUNT(oi.id) as item_count
|
||||
FROM orders o
|
||||
LEFT JOIN order_items oi ON oi.order_id = o.id
|
||||
WHERE o.restaurant_id = ?
|
||||
WHERE o.shop_id = ?
|
||||
GROUP BY o.id, o.status, o.created_at
|
||||
ORDER BY o.created_at DESC
|
||||
LIMIT 10
|
||||
@@ -492,7 +484,7 @@ export class OrdersService {
|
||||
INNER JOIN orders o ON oi.order_id = o.id
|
||||
INNER JOIN variants v ON oi.variant_id = v.id
|
||||
INNER JOIN products f ON v.product_id = f.id
|
||||
WHERE o.restaurant_id = ?
|
||||
WHERE o.shop_id = ?
|
||||
AND o.created_at >= ?
|
||||
AND o.created_at <= ?
|
||||
AND o.status NOT IN ('pendingPayment', 'canceled')
|
||||
|
||||
@@ -29,5 +29,5 @@ export interface OrderPaymentContext {
|
||||
method: PaymentMethodEnum;
|
||||
gateway: PaymentGatewayEnum | null;
|
||||
merchantId: string | null;
|
||||
restaurantDomain: string | null;
|
||||
shopDomain: string | null;
|
||||
}
|
||||
|
||||
@@ -83,7 +83,7 @@ export class PaymentsService {
|
||||
method: pm.method,
|
||||
gateway: pm.gateway ?? null,
|
||||
merchantId: pm.merchantId ?? null,
|
||||
restaurantDomain: pm.shop.domain ?? null,
|
||||
shopDomain: pm.shop.domain ?? null,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -170,7 +170,7 @@ export class PaymentsService {
|
||||
amount: ctx.amount,
|
||||
orderId: ctx.order.id,
|
||||
merchantId: ctx.merchantId!,
|
||||
domain: ctx.restaurantDomain!,
|
||||
domain: ctx.shopDomain!,
|
||||
});
|
||||
|
||||
payment.gateway = ctx.gateway;
|
||||
@@ -280,8 +280,8 @@ export class PaymentsService {
|
||||
payment.order.status = OrderStatus.CANCELED;
|
||||
}
|
||||
|
||||
async findOneOrFail(paymentId: string): Promise<Payment> {
|
||||
const payment=await this.paymentRepository.findOne({ id: paymentId });
|
||||
async findOneOrFail(paymentId: string): Promise<Payment> {
|
||||
const payment = await this.paymentRepository.findOne({ id: paymentId });
|
||||
if (!payment) {
|
||||
throw new NotFoundException(PaymentMessage.PAYMENT_NOT_FOUND);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user