send noti after successfull online payment
This commit is contained in:
@@ -15,6 +15,7 @@ export class OrderListeners {
|
|||||||
private readonly logger = new Logger(OrderListeners.name);
|
private readonly logger = new Logger(OrderListeners.name);
|
||||||
private orderCreatedSmsTemplateId: string;
|
private orderCreatedSmsTemplateId: string;
|
||||||
private orderStatusChangedSmsTemplateId: string;
|
private orderStatusChangedSmsTemplateId: string;
|
||||||
|
private orderCompletedSmsTemplateId: string;
|
||||||
constructor(
|
constructor(
|
||||||
private readonly adminService: AdminRepository,
|
private readonly adminService: AdminRepository,
|
||||||
private readonly OrderRepository: OrderRepository,
|
private readonly OrderRepository: OrderRepository,
|
||||||
@@ -23,6 +24,7 @@ export class OrderListeners {
|
|||||||
) {
|
) {
|
||||||
this.orderCreatedSmsTemplateId = this.configService.get<string>('SMS_PATTERN_ORDER_CREATED') ?? '123';
|
this.orderCreatedSmsTemplateId = this.configService.get<string>('SMS_PATTERN_ORDER_CREATED') ?? '123';
|
||||||
this.orderStatusChangedSmsTemplateId = this.configService.get<string>('SMS_PATTERN_ORDER_STATUS_CHANGE') ?? '123';
|
this.orderStatusChangedSmsTemplateId = this.configService.get<string>('SMS_PATTERN_ORDER_STATUS_CHANGE') ?? '123';
|
||||||
|
this.orderCompletedSmsTemplateId = this.configService.get<string>('SMS_PATTERN_ORDER_STATUS_COMPLETED') ?? '123';
|
||||||
}
|
}
|
||||||
|
|
||||||
private getStatusFarsi(status: OrderStatus): string {
|
private getStatusFarsi(status: OrderStatus): string {
|
||||||
@@ -103,33 +105,62 @@ export class OrderListeners {
|
|||||||
userId: event.userId,
|
userId: event.userId,
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
await this.notificationService.sendNotification({
|
if(event.newStatus === OrderStatus.COMPLETED) {
|
||||||
restaurantId: event.restaurantId,
|
await this.notificationService.sendNotification({
|
||||||
message: {
|
restaurantId: event.restaurantId,
|
||||||
title: NotifTitleEnum.ORDER_STATUS_CHANGED,
|
message: {
|
||||||
content: `وضعیت سفارش شماره ${event.orderNumber} به ${this.getStatusFarsi(event.newStatus)} تغییر کرد`,
|
title: NotifTitleEnum.ORDER_STATUS_CHANGED,
|
||||||
sms: {
|
content: `لطفا ثبت نظر سفارش ${event.orderNumber} به اپ مراجعه کنید`,
|
||||||
templateId: this.orderStatusChangedSmsTemplateId,
|
sms: {
|
||||||
parameters: {
|
templateId: this.orderCreatedSmsTemplateId ,
|
||||||
orderNumber: event.orderNumber,
|
parameters: {
|
||||||
status: event.newStatus,
|
orderNumber: event.orderNumber,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
pushNotif: {
|
||||||
|
title: `تغییر وضعیت سفارش`,
|
||||||
|
content: `لطفا ثبت نظر سفارش ${event.orderNumber} به اپ مراجعه کنید`,
|
||||||
|
icon: `/`,
|
||||||
|
action: {
|
||||||
|
type: NotifTitleEnum.ORDER_STATUS_CHANGED,
|
||||||
|
url: ``,
|
||||||
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
pushNotif: {
|
recipients,
|
||||||
title: `تغییر وضعیت سفارش`,
|
metadata: {
|
||||||
|
priority: 1,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
}else{
|
||||||
|
await this.notificationService.sendNotification({
|
||||||
|
restaurantId: event.restaurantId,
|
||||||
|
message: {
|
||||||
|
title: NotifTitleEnum.ORDER_STATUS_CHANGED,
|
||||||
content: `وضعیت سفارش شماره ${event.orderNumber} به ${this.getStatusFarsi(event.newStatus)} تغییر کرد`,
|
content: `وضعیت سفارش شماره ${event.orderNumber} به ${this.getStatusFarsi(event.newStatus)} تغییر کرد`,
|
||||||
icon: `/`,
|
sms: {
|
||||||
action: {
|
templateId: this.orderStatusChangedSmsTemplateId,
|
||||||
type: NotifTitleEnum.ORDER_STATUS_CHANGED,
|
parameters: {
|
||||||
url: ``,
|
orderNumber: event.orderNumber,
|
||||||
|
status: this.getStatusFarsi(event.newStatus),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
pushNotif: {
|
||||||
|
title: `تغییر وضعیت سفارش`,
|
||||||
|
content: `وضعیت سفارش شماره ${event.orderNumber} به ${this.getStatusFarsi(event.newStatus)} تغییر کرد`,
|
||||||
|
icon: `/`,
|
||||||
|
action: {
|
||||||
|
type: NotifTitleEnum.ORDER_STATUS_CHANGED,
|
||||||
|
url: ``,
|
||||||
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
recipients,
|
||||||
recipients,
|
metadata: {
|
||||||
metadata: {
|
priority: 1,
|
||||||
priority: 1,
|
},
|
||||||
},
|
});
|
||||||
});
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
this.logger.error(
|
this.logger.error(
|
||||||
`Failed to send notification for order status changed event: ${event.restaurantId}`,
|
`Failed to send notification for order status changed event: ${event.restaurantId}`,
|
||||||
|
|||||||
@@ -126,9 +126,6 @@ export class PaymentListeners {
|
|||||||
);
|
);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (order.paymentMethod.method === PaymentMethodEnum.Online) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
const userRecipients = [
|
const userRecipients = [
|
||||||
{
|
{
|
||||||
userId: order.user.id,
|
userId: order.user.id,
|
||||||
|
|||||||
Reference in New Issue
Block a user