phone
This commit is contained in:
@@ -50,6 +50,7 @@ export class NotificationService {
|
|||||||
})),
|
})),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
// add sms notifications to queue
|
// add sms notifications to queue
|
||||||
if (preference?.channels?.includes(NotifChannelEnum.SMS)) {
|
if (preference?.channels?.includes(NotifChannelEnum.SMS)) {
|
||||||
await this.queueService.addBulkSmsNotifications(
|
await this.queueService.addBulkSmsNotifications(
|
||||||
@@ -140,6 +141,7 @@ export class NotificationService {
|
|||||||
},
|
},
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
async findByAdminAndRestaurant(adminId: string, restaurantId: string, limit = 50): Promise<Notification[]> {
|
async findByAdminAndRestaurant(adminId: string, restaurantId: string, limit = 50): Promise<Notification[]> {
|
||||||
return this.em.find(
|
return this.em.find(
|
||||||
Notification,
|
Notification,
|
||||||
|
|||||||
@@ -32,10 +32,11 @@ export class SmsService {
|
|||||||
name,
|
name,
|
||||||
value: value.toString(),
|
value: value.toString(),
|
||||||
}));
|
}));
|
||||||
|
const cleanedPhone = this.formatPhone(phone);
|
||||||
|
|
||||||
const smsData: ISmsBodyParameters = {
|
const smsData: ISmsBodyParameters = {
|
||||||
Parameters: parametersArray,
|
Parameters: parametersArray,
|
||||||
Mobile: phone,
|
Mobile: cleanedPhone,
|
||||||
TemplateId: templateId,
|
TemplateId: templateId,
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -57,4 +58,22 @@ export class SmsService {
|
|||||||
throw new HttpException('The SMS was not sent. Please try again later.', HttpStatus.BAD_GATEWAY);
|
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}`;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user