From 2f21791e23257910486bb3f2345da19ba6c980fc Mon Sep 17 00:00:00 2001 From: morteza-mortezai Date: Sun, 14 Dec 2025 11:57:35 +0330 Subject: [PATCH] phone --- .../services/notification.service.ts | 2 ++ src/modules/utils/sms.service.ts | 21 ++++++++++++++++++- 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/src/modules/notifications/services/notification.service.ts b/src/modules/notifications/services/notification.service.ts index a3b9e0c..f49bbfc 100644 --- a/src/modules/notifications/services/notification.service.ts +++ b/src/modules/notifications/services/notification.service.ts @@ -50,6 +50,7 @@ export class NotificationService { })), ); } + // add sms notifications to queue if (preference?.channels?.includes(NotifChannelEnum.SMS)) { await this.queueService.addBulkSmsNotifications( @@ -140,6 +141,7 @@ export class NotificationService { }, ); } + async findByAdminAndRestaurant(adminId: string, restaurantId: string, limit = 50): Promise { return this.em.find( Notification, diff --git a/src/modules/utils/sms.service.ts b/src/modules/utils/sms.service.ts index d941f69..9756ced 100644 --- a/src/modules/utils/sms.service.ts +++ b/src/modules/utils/sms.service.ts @@ -32,10 +32,11 @@ export class SmsService { name, value: value.toString(), })); + const cleanedPhone = this.formatPhone(phone); const smsData: ISmsBodyParameters = { Parameters: parametersArray, - Mobile: phone, + Mobile: cleanedPhone, TemplateId: templateId, }; @@ -57,4 +58,22 @@ export class SmsService { throw new HttpException('The SMS was not sent. Please try again later.', HttpStatus.BAD_GATEWAY); } } + formatPhone(phone: string): string { + // remove spaces, dashes, parentheses + phone = phone.replace(/[^\d+]/g, ''); + + if (phone.startsWith('+98')) { + return phone; + } + + if (phone.startsWith('98')) { + return `+${phone}`; + } + + if (phone.startsWith('0')) { + return `+98${phone.slice(1)}`; + } + + return `+98${phone}`; + } }