refactor: the invoice queue logic

This commit is contained in:
mahyargdz
2025-04-21 14:51:54 +03:30
parent c330428ce5
commit e7d547f19b
10 changed files with 121 additions and 31 deletions
+2
View File
@@ -40,6 +40,8 @@ export type TemplateParams =
| "newBalance"
| "reason"
| "dueDate"
| "lateFee"
| "paidDate"
| "user"
| "subject"
| "planName"
+47 -16
View File
@@ -366,12 +366,12 @@ export class SmsService {
}
}
//************************************************* */
async sendInvoicePaidSms(mobile: string, invoiceId: string, price: number, date: string) {
async sendInvoicePaidSms(mobile: string, invoiceId: string, amount: number, paidDate: string) {
const smsData: ISmsVerifyBody = {
Parameters: [
{ name: "invoiceId", value: invoiceId },
{ name: "price", value: Intl.NumberFormat("fa-IR").format(price) },
{ name: "date", value: date },
{ name: "amount", value: amount.toString() },
{ name: "paidDate", value: paidDate },
],
Mobile: mobile,
TemplateId: this.smsConfigs.SMS_PATTERN_INVOICE_PAID,
@@ -399,15 +399,15 @@ export class SmsService {
//************************************************* */
async sendInvoicePaymentReminderSms(mobile: string, invoiceId: string, price: number, dueDate: string) {
async sendInvoicePaymentReminderSms(mobile: string, invoiceId: string, amount: number, dueDate: string) {
const smsData: ISmsVerifyBody = {
Parameters: [
{ name: "invoiceId", value: invoiceId },
{ name: "price", value: Intl.NumberFormat("fa-IR").format(price) },
{ name: "amount", value: amount.toString() },
{ name: "dueDate", value: dueDate },
],
Mobile: mobile,
TemplateId: this.smsConfigs.SMS_PATTERN_INVOICE_PAYMENT_REMINDER,
TemplateId: this.smsConfigs.SMS_PATTERN_INVOICE_REMINDER,
};
try {
@@ -418,18 +418,51 @@ export class SmsService {
})
.pipe(
catchError((err: AxiosError) => {
this.logger.error("error in sending invoice payment reminder sms", err);
throw new InternalServerErrorException("error in sending invoice payment reminder sms");
this.logger.error("error in sending invoice reminder sms", err);
throw new InternalServerErrorException("error in sending invoice reminder sms");
}),
),
);
return data;
} catch (error) {
this.logger.error("error in sending sms", error);
// throw new InternalServerErrorException("error in sending sms");
}
}
// //************************************************* */
//************************************************* */
async sendInvoiceOverdueSms(mobile: string, invoiceId: string, amount: number, lateFee: number, dueDate: string) {
const smsData: ISmsVerifyBody = {
Parameters: [
{ name: "invoiceId", value: invoiceId },
{ name: "amount", value: amount.toString() },
{ name: "lateFee", value: lateFee.toString() },
{ name: "dueDate", value: dueDate },
],
Mobile: mobile,
TemplateId: this.smsConfigs.SMS_PATTERN_INVOICE_OVERDUE,
};
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 invoice overdue sms", err);
throw new InternalServerErrorException("error in sending invoice overdue sms");
}),
),
);
return data;
} catch (error) {
this.logger.error("error in sending sms", error);
}
}
//************************************************* */
async sendRecurringInvoiceDraftSms(adminMobile: string, invoiceId: string, price: number) {
const smsData: ISmsVerifyBody = {
@@ -461,7 +494,7 @@ export class SmsService {
}
}
// //************************************************* */
//************************************************* */
async sendBlockServiceSms(mobile: string, invoiceId: string, planName: string) {
const smsData: ISmsVerifyBody = {
@@ -493,23 +526,21 @@ export class SmsService {
}
}
// //************************************************* */
//************************************************* */
// sendCreateServiceSms(userPhone: string, serviceName: any) {
// throw new Error("Method not implemented.");
// }
// //************************************************* */
//************************************************* */
// sendUnblockServiceSms(userPhone: string, serviceName: any) {
// throw new Error("Method not implemented.");
// }
// //************************************************* */
//************************************************* */
// sendBlockServiceSms(userPhone: string, serviceName: any) {
// throw new Error("Method not implemented.");
// }
// //************************************************* */
//************************************************* */
async getSmsLines() {