notif after rest create order
deploy to danak / build_and_deploy (push) Has been cancelled

This commit is contained in:
2026-06-23 12:53:55 +03:30
parent 0036e9e97f
commit a565f93044
4 changed files with 40 additions and 8 deletions
@@ -24,7 +24,7 @@ export interface NotifRequestMessage {
templateId: string;
parameters?: Record<string, string>;
};
pushNotif: {
pushNotif?: {
title: string;
content: string;
icon: string;
@@ -1,11 +1,14 @@
import type { OrderStatus, StatusTransitionRef } from '../interface/order.interface';
export type OrderCreatedRef = 'user' | 'restaurant';
export class OrderCreatedEvent {
constructor(
public readonly orderId: string,
public readonly restaurantId: string,
public readonly orderNumber: string,
public readonly total: number,
public readonly ref: OrderCreatedRef,
) {}
}
@@ -55,17 +55,46 @@ export class OrderListeners {
`Order created event received: ${event.orderId} for restaurant: ${event.restaurantId} and order number: ${event.orderNumber}`,
);
const order = await this.OrderRepository.findOne(event.orderId);
const order = await this.OrderRepository.findOne(
{ id: event.orderId },
{ populate: ['user', 'paymentMethod'] as never },
);
if (!order?.user?.id) {
this.logger.error(`Order user not found for order created event: ${event.orderId}`);
return;
}
if (order?.paymentMethod.method === PaymentMethodEnum.Online) {
return;
}
if (event.ref === 'restaurant') {
await this.notificationService.sendNotification({
restaurantId: event.restaurantId,
message: {
title: NotifTitleEnum.ORDER_CREATED,
content: `سفارش شماره ${event.orderNumber} با مبلغ ${event.total} تومان با موفقیت ایجاد شد`,
sms: {
templateId: this.orderCreatedSmsTemplateId,
parameters: {
orderNumber: event.orderNumber,
total: event.total.toString(),
},
},
},
recipients: [{ userId: order.user.id }],
metadata: {
priority: 1,
},
});
return;
}
// get admnin os restuaraant that have order permissuins
// If order is created by user, notify both restaurant admins and the user.
const admins = await this.adminService.findAdminsWithPermission(event.restaurantId, Permission.NEW_ORDER_NOTIFICATION);
const recipients = admins.map(admin => ({
adminId: admin.id,
}));
const recipients = [
...admins.map(admin => ({ adminId: admin.id })),
{ userId: order.user.id },
];
await this.notificationService.sendNotification({
restaurantId: event.restaurantId,
@@ -141,7 +141,7 @@ console.log(cart);
const { paymentUrl } = await this.paymentsService.payOrder(order.id);
this.eventEmitter.emit(
OrderCreatedEvent.name,
new OrderCreatedEvent(order.id, restaurantId, String(order?.orderNumber) || '', order.total),
new OrderCreatedEvent(order.id, restaurantId, String(order?.orderNumber) || '', order.total, 'user'),
);
return { paymentUrl, order };
@@ -228,7 +228,7 @@ console.log(cart);
this.eventEmitter.emit(
OrderCreatedEvent.name,
new OrderCreatedEvent(order.id, restaurantId, String(order?.orderNumber) || '', order.total),
new OrderCreatedEvent(order.id, restaurantId, String(order?.orderNumber) || '', order.total, 'restaurant'),
);
return order;