fix(professors): handle nationalId and phone aliases with trimming; update payment sms
This commit is contained in:
@@ -61,40 +61,31 @@ const sendClassReminderSms = async (receiver, className, time, place = '', userI
|
||||
});
|
||||
};
|
||||
|
||||
const sendInvoiceCreatedSms = async (receiver, payloadOrAmount, userId = null, extraCourse = '') => {
|
||||
const isObject = typeof payloadOrAmount === 'object' && payloadOrAmount !== null;
|
||||
const resolvedUserId = (isObject && payloadOrAmount.userId)
|
||||
? payloadOrAmount.userId
|
||||
: (userId || await resolveUserIdByPhone(receiver));
|
||||
const sendInvoiceCreatedSms = async (receiver, payload, userId = null) => {
|
||||
const resolvedUserId = userId || await resolveUserIdByPhone(receiver);
|
||||
const { templateId, variables } = await getSmsTemplate('invoiceCreated');
|
||||
|
||||
let fullName = '';
|
||||
let amount = 0;
|
||||
let amount = '';
|
||||
let course = '';
|
||||
|
||||
if (isObject) {
|
||||
fullName = payloadOrAmount.fullName || '';
|
||||
amount = payloadOrAmount.amount ?? 0;
|
||||
course = payloadOrAmount.course || '';
|
||||
if (typeof payload === 'object' && payload !== null) {
|
||||
fullName = payload.fullName || '';
|
||||
amount = payload.amount != null ? String(payload.amount) : '';
|
||||
course = payload.course || '';
|
||||
} else {
|
||||
amount = payloadOrAmount;
|
||||
course = typeof extraCourse === 'string' ? extraCourse : '';
|
||||
amount = String(payload || '');
|
||||
}
|
||||
|
||||
if (!fullName && resolvedUserId) {
|
||||
const user = await User.findById(resolvedUserId).select('name').lean();
|
||||
fullName = user?.name || '';
|
||||
}
|
||||
|
||||
const { templateId, variables } = await getSmsTemplate('invoiceCreated');
|
||||
const amountLabel = String(amount);
|
||||
const fullNameLabel = String(fullName || '').trim();
|
||||
const courseLabel = String(course || '').trim();
|
||||
const courseLabel = course || '-';
|
||||
const fullNameLabel = fullName || 'کارآموز';
|
||||
|
||||
return recordAndSend({
|
||||
userId: resolvedUserId,
|
||||
channel: 'sms',
|
||||
subject: 'ایجاد صورتحساب',
|
||||
body: `صورتحساب جدید به مبلغ ${amountLabel} تومان بابت دوره «${courseLabel || '-'}» برای ${fullNameLabel || 'کارآموز'} صادر شد.`,
|
||||
body: `کارآموز عزیز، ${fullNameLabel}، یک صورتحساب به مبلغ ${amountLabel} تومان بابت دوره «${courseLabel}» برای شما ایجاد شد.`,
|
||||
relatedEvent: 'payment.created',
|
||||
sendFn: () => sendSingleSms(receiver, templateId, buildSmsParameters(variables, {
|
||||
fullName: fullNameLabel,
|
||||
|
||||
Reference in New Issue
Block a user