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:
2026-08-16 06:58:08 +03:30
parent a6c760c3b7
commit 72be01fee3
25 changed files with 601 additions and 43 deletions
+37 -4
View File
@@ -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