update
This commit is contained in:
@@ -5,15 +5,19 @@ import { OrderCreatedEvent } from '../events/order.events';
|
||||
import { Permission } from 'src/common/enums/permission.enum';
|
||||
import { NotifTitleEnum } from 'src/modules/notifications/interfaces/notification.interface';
|
||||
import { NotificationService } from 'src/modules/notifications/services/notification.service';
|
||||
import { ConfigService } from '@nestjs/config';
|
||||
|
||||
@Injectable()
|
||||
export class OrderListeners {
|
||||
private readonly logger = new Logger(OrderListeners.name);
|
||||
|
||||
private orderCreatedSmsTemplateId: string;
|
||||
constructor(
|
||||
private readonly adminService: AdminRepository,
|
||||
private readonly notificationService: NotificationService,
|
||||
) {}
|
||||
private readonly configService: ConfigService,
|
||||
) {
|
||||
this.orderCreatedSmsTemplateId = this.configService.get<string>('ORDER_CREATED_SMS_TEMPLATE_ID') ?? '123';
|
||||
}
|
||||
|
||||
@OnEvent(OrderCreatedEvent.name)
|
||||
async handleOrderCreated(event: OrderCreatedEvent) {
|
||||
@@ -21,7 +25,7 @@ export class OrderListeners {
|
||||
this.logger.log(
|
||||
`Order created event received: ${event.orderId} for restaurant: ${event.restaurantId} and order number: ${event.orderNumber}`,
|
||||
);
|
||||
// get admnin os restuaraant that have pager permissuins
|
||||
// get admnin os restuaraant that have order permissuins
|
||||
const admins = await this.adminService.findAdminsWithPermission(event.restaurantId, Permission.MANAGE_ORDERS);
|
||||
const recipients = admins.map(admin => ({
|
||||
adminId: admin.id,
|
||||
@@ -32,7 +36,7 @@ export class OrderListeners {
|
||||
title: NotifTitleEnum.ORDER_CREATED,
|
||||
content: `Order ${event.orderNumber} has been created successfully`,
|
||||
sms: {
|
||||
templateId: '1234567890',
|
||||
templateId: this.orderCreatedSmsTemplateId,
|
||||
parameters: {
|
||||
orderNumber: event.orderNumber,
|
||||
},
|
||||
@@ -54,7 +58,7 @@ export class OrderListeners {
|
||||
});
|
||||
} catch (error) {
|
||||
this.logger.error(
|
||||
`Failed to send notification for pager created event: ${event.restaurantId}`,
|
||||
`Failed to send notification for order created event: ${event.restaurantId}`,
|
||||
error instanceof Error ? error.stack : String(error),
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user