feat: send account and invoice SMS from stored template IDs

Move sms.ir template IDs out of env into settings so SuperAdmin can manage them, and record every outbound SMS status in notifications.
This commit is contained in:
2026-08-15 18:37:44 +03:30
parent 23edffba6a
commit 3160f07873
13 changed files with 261 additions and 22 deletions
+50
View File
@@ -0,0 +1,50 @@
'use strict';
const SMS_TEMPLATE_DEFS = [
{
key: 'accountCreated',
label: 'ایجاد حساب کاربری',
variables: ['user', 'password'],
envKey: 'SMS_TEMPLATE_ACCOUNT_CREATED'
},
{
key: 'classRegistered',
label: 'ثبت‌نام در کلاس',
variables: ['className'],
envKey: 'SMS_TEMPLATE_CLASS_REGISTERED'
},
{
key: 'classReminder',
label: 'یادآوری کلاس',
variables: ['className', 'time', 'place'],
envKey: 'SMS_TEMPLATE_CLASS_REMINDER'
},
{
key: 'invoiceCreated',
label: 'ایجاد صورتحساب',
variables: ['amount'],
envKey: 'SMS_TEMPLATE_INVOICE_CREATED'
}
];
const SMS_TEMPLATE_KEYS = SMS_TEMPLATE_DEFS.map((def) => def.key);
const envFallbackFor = (def) => {
if (!def?.envKey) return '';
return String(process.env[def.envKey] || '').trim();
};
const sanitizeTemplateId = (value) => {
if (value == null) return '';
const digits = String(value).trim();
if (!digits) return '';
if (!/^\d{1,20}$/.test(digits)) return null;
return digits;
};
module.exports = {
SMS_TEMPLATE_DEFS,
SMS_TEMPLATE_KEYS,
envFallbackFor,
sanitizeTemplateId
};