chore: add new method for sms service and notification service

This commit is contained in:
mahyargdz
2025-05-04 12:27:21 +03:30
parent 8fe1d398a6
commit 3d24cee972
10 changed files with 451 additions and 8 deletions
+4 -1
View File
@@ -45,4 +45,7 @@ export type TemplateParams =
| "user"
| "subject"
| "planName"
| "message";
| "message"
| "blogTitle"
| "fullName"
| "mobile";
@@ -153,4 +153,23 @@ export class EmailService {
this.logger.error("error in sending payment cancellation email", error);
}
}
async sendAdminNotificationEmail(data: { userEmail: string; title: string; message: string }) {
const emailData = {
to: data.userEmail,
subject: data.title,
template: "admin-notification",
context: {
title: data.title,
message: data.message,
},
};
try {
await this.mailerService.sendMail(emailData);
} catch (error) {
this.logger.error("error in sending admin notification email", error);
throw new InternalServerErrorException("error in sending admin notification email");
}
}
}
+186 -2
View File
@@ -490,7 +490,7 @@ export class SmsService {
return data;
} catch (error) {
this.logger.error("error in sending sms", error);
throw new InternalServerErrorException("error in sending sms");
// throw new InternalServerErrorException("error in sending sms");
}
}
@@ -522,7 +522,7 @@ export class SmsService {
return data;
} catch (error) {
this.logger.error("error in sending sms", error);
throw new InternalServerErrorException("error in sending sms");
// throw new InternalServerErrorException("error in sending sms");
}
}
@@ -604,4 +604,188 @@ export class SmsService {
}
//************************************************* */
async sendBlogNewCommentSms(mobile: string, blogTitle: string, fullName: string) {
const smsData: ISmsVerifyBody = {
Parameters: [
{ name: "blogTitle", value: blogTitle },
{ name: "fullName", value: fullName },
],
Mobile: mobile,
TemplateId: this.smsConfigs.SMS_PATTERN_BLOG_NEW_COMMENT,
};
try {
const { data } = await firstValueFrom(
this.httpService
.post<ISmsVerifyResponse>(`${this.smsConfigs.API_URL}/send/verify`, smsData, {
headers: { "X-API-KEY": this.smsConfigs.API_KEY },
})
.pipe(
catchError((err: AxiosError) => {
this.logger.error("error in sending blog new comment sms", err);
throw new InternalServerErrorException("error in sending blog new comment sms");
}),
),
);
return data;
} catch (error) {
this.logger.error("error in sending sms", error);
// throw new InternalServerErrorException("error in sending sms");
}
}
//************************************************* */
async sendNewServiceReviewSms(mobile: string, serviceName: string, fullName: string) {
const smsData: ISmsVerifyBody = {
Parameters: [
{ name: "serviceName", value: serviceName },
{ name: "fullName", value: fullName },
],
Mobile: mobile,
TemplateId: this.smsConfigs.SMS_PATTERN_NEW_SERVICE_REVIEW,
};
try {
const { data } = await firstValueFrom(
this.httpService
.post<ISmsVerifyResponse>(`${this.smsConfigs.API_URL}/send/verify`, smsData, {
headers: { "X-API-KEY": this.smsConfigs.API_KEY },
})
.pipe(
catchError((err: AxiosError) => {
this.logger.error("error in sending new service review sms", err);
throw new InternalServerErrorException("error in sending new service review sms");
}),
),
);
return data;
} catch (error) {
this.logger.error("error in sending sms", error);
}
}
//************************************************* */
async sendNewCustomerSms(mobile: string, fullName: string) {
const smsData: ISmsVerifyBody = {
Parameters: [
{ name: "fullName", value: fullName },
{ name: "mobile", value: mobile },
],
Mobile: mobile,
TemplateId: this.smsConfigs.SMS_PATTERN_NEW_CUSTOMER,
};
try {
const { data } = await firstValueFrom(
this.httpService
.post<ISmsVerifyResponse>(`${this.smsConfigs.API_URL}/send/verify`, smsData, {
headers: { "X-API-KEY": this.smsConfigs.API_KEY },
})
.pipe(
catchError((err: AxiosError) => {
this.logger.error("error in sending new customer sms", err);
throw new InternalServerErrorException("error in sending new customer sms");
}),
),
);
return data;
} catch (error) {
this.logger.error("error in sending sms", error);
}
}
//************************************************* */
async sendNewSubscriptionSms(mobile: string, serviceName: string, fullName: string, date: string) {
const smsData: ISmsVerifyBody = {
Parameters: [
{ name: "serviceName", value: serviceName },
{ name: "fullName", value: fullName },
{ name: "date", value: date },
],
Mobile: mobile,
TemplateId: this.smsConfigs.SMS_PATTERN_NEW_SUBSCRIPTION,
};
try {
const { data } = await firstValueFrom(
this.httpService
.post<ISmsVerifyResponse>(`${this.smsConfigs.API_URL}/send/verify`, smsData, {
headers: { "X-API-KEY": this.smsConfigs.API_KEY },
})
.pipe(
catchError((err: AxiosError) => {
this.logger.error("error in sending new subscription sms", err);
throw new InternalServerErrorException("error in sending new subscription sms");
}),
),
);
return data;
} catch (error) {
this.logger.error("error in sending sms", error);
}
}
//************************************************* */
async sendGlobalNewTicketSms(mobile: string, ticketId: string, subject: string, fullName: string) {
const smsData: ISmsVerifyBody = {
Parameters: [
{ name: "ticketId", value: ticketId },
{ name: "subject", value: subject },
{ name: "fullName", value: fullName },
],
Mobile: mobile,
TemplateId: this.smsConfigs.SMS_PATTERN_NEW_TICKET_GLOBAL,
};
try {
const { data } = await firstValueFrom(
this.httpService
.post<ISmsVerifyResponse>(`${this.smsConfigs.API_URL}/send/verify`, smsData, {
headers: { "X-API-KEY": this.smsConfigs.API_KEY },
})
.pipe(
catchError((err: AxiosError) => {
this.logger.error("error in sending global new ticket sms", err);
throw new InternalServerErrorException("error in sending global new ticket sms");
}),
),
);
return data;
} catch (error) {
this.logger.error("error in sending sms", error);
}
}
//************************************************* */
async sendNewCriticismSms(mobile: string, title: string, fullName: string) {
const smsData: ISmsVerifyBody = {
Parameters: [
{ name: "title", value: title },
{ name: "fullName", value: fullName },
],
Mobile: mobile,
TemplateId: this.smsConfigs.SMS_PATTERN_NEW_CRITICISM,
};
try {
const { data } = await firstValueFrom(
this.httpService
.post<ISmsVerifyResponse>(`${this.smsConfigs.API_URL}/send/verify`, smsData, {
headers: { "X-API-KEY": this.smsConfigs.API_KEY },
})
.pipe(
catchError((err: AxiosError) => {
this.logger.error("error in sending new criticism sms", err);
throw new InternalServerErrorException("error in sending new criticism sms");
}),
),
);
return data;
} catch (error) {
this.logger.error("error in sending sms", error);
}
}
//************************************************* */
}