feat: add messaging toggles, password reset SMS, and payment discounts
Allow SuperAdmin to disable SMS, email, and bot from dashboard settings on top of env flags. Add admin password reset with credentials SMS, plus payment discounts, notes, and payable amount handling.
This commit is contained in:
@@ -13,7 +13,15 @@ const resolveUserIdByPhone = async (phoneNumber) => {
|
||||
return user?._id || null;
|
||||
};
|
||||
|
||||
const sendAccountCreatedSms = async (receiver, username, password, userId = null) => {
|
||||
const sendAccountCredentialsSms = async ({
|
||||
receiver,
|
||||
username,
|
||||
password,
|
||||
userId = null,
|
||||
subject,
|
||||
body,
|
||||
relatedEvent
|
||||
}) => {
|
||||
const resolvedUserId = userId || await resolveUserIdByPhone(receiver);
|
||||
let fullName = '';
|
||||
if (resolvedUserId) {
|
||||
@@ -24,9 +32,9 @@ const sendAccountCreatedSms = async (receiver, username, password, userId = null
|
||||
return recordAndSend({
|
||||
userId: resolvedUserId,
|
||||
channel: 'sms',
|
||||
subject: 'ایجاد حساب کاربری',
|
||||
body: `حساب کاربری شما ایجاد شد. نام کاربری: ${username}`,
|
||||
relatedEvent: 'user.created',
|
||||
subject,
|
||||
body,
|
||||
relatedEvent,
|
||||
sendFn: () => sendSingleSms(receiver, templateId, buildSmsParameters(variables, {
|
||||
username,
|
||||
password,
|
||||
@@ -38,6 +46,30 @@ const sendAccountCreatedSms = async (receiver, username, password, userId = null
|
||||
});
|
||||
};
|
||||
|
||||
const sendAccountCreatedSms = async (receiver, username, password, userId = null) => {
|
||||
return sendAccountCredentialsSms({
|
||||
receiver,
|
||||
username,
|
||||
password,
|
||||
userId,
|
||||
subject: 'ایجاد حساب کاربری',
|
||||
body: `حساب کاربری شما ایجاد شد. نام کاربری: ${username}`,
|
||||
relatedEvent: 'user.created'
|
||||
});
|
||||
};
|
||||
|
||||
const sendPasswordResetSms = async (receiver, username, password, userId = null) => {
|
||||
return sendAccountCredentialsSms({
|
||||
receiver,
|
||||
username,
|
||||
password,
|
||||
userId,
|
||||
subject: 'بازنشانی رمز عبور',
|
||||
body: `رمز عبور شما بازنشانی شد. نام کاربری: ${username}`,
|
||||
relatedEvent: 'user.password_reset'
|
||||
});
|
||||
};
|
||||
|
||||
const sendClassRegisteredSms = async (receiver, className, userId = null, extraContext = {}) => {
|
||||
const resolvedUserId = userId || await resolveUserIdByPhone(receiver);
|
||||
let fullName = extraContext.fullName || '';
|
||||
@@ -143,6 +175,7 @@ const sendInvoiceCreatedSms = async (receiver, payload, userId = null) => {
|
||||
|
||||
module.exports = {
|
||||
sendAccountCreatedSms,
|
||||
sendPasswordResetSms,
|
||||
sendClassRegisteredSms,
|
||||
sendClassReminderSms,
|
||||
sendInvoiceCreatedSms
|
||||
|
||||
Reference in New Issue
Block a user