mirror of
https://github.com/rgrgogu/new_starr.git
synced 2026-09-27 00:12:54 +08:00
60 lines
2.1 KiB
JavaScript
60 lines
2.1 KiB
JavaScript
/***********************************************************************************************************************************************************************
|
|
* File Name: notification_template_enrichers.data.js
|
|
* Type of Program: Data / Registry
|
|
* Description: Admin-edited notification templates are plain text — no
|
|
* conditionals or expressions allowed. Any type that used to
|
|
* branch on data in JS (e.g. task_overdue's singular/plural
|
|
* wording) gets that branch precomputed here into flat
|
|
* placeholder keys BEFORE substitution, so the stored title/
|
|
* message only ever needs straight {{key}} swaps.
|
|
* Mirrors data/email_template_enrichers.data.js.
|
|
* Author: Kenneth Obsequio (@lash0000)
|
|
* Date Created: Jul. 3, 2026
|
|
***********************************************************************************************************************************************************************/
|
|
const { fmtDate } = require('../utils/datetime.util');
|
|
|
|
const ENRICHERS = {
|
|
task_overdue: (data) => ({
|
|
...data,
|
|
task_word: Number(data.count) === 1 ? 'task was' : 'tasks were',
|
|
}),
|
|
|
|
user_task_overdue: (data) => ({
|
|
...data,
|
|
task_label: Number(data.count) === 1 ? '1 task has' : `${data.count} tasks have`,
|
|
}),
|
|
|
|
task_reminder: (data) => ({
|
|
...data,
|
|
deadline: fmtDate(data.deadline),
|
|
}),
|
|
|
|
welcome: (data) => {
|
|
const greeting = data.accType === 'admin'
|
|
? 'Welcome, Administrator!'
|
|
: data.accType === 'staff'
|
|
? 'Welcome to the Philproperties team!'
|
|
: 'Welcome to Philproperties!';
|
|
return {
|
|
...data,
|
|
greeting,
|
|
group_suffix: data.groupName ? ` You have been added to ${data.groupName}.` : '',
|
|
};
|
|
},
|
|
|
|
assessment_updated: (data) => ({
|
|
...data,
|
|
assessmentTitle: data.assessmentTitle || 'Course Assessment',
|
|
courseTitle: data.courseTitle || 'your course',
|
|
}),
|
|
|
|
tier_expired: (data) => ({
|
|
...data,
|
|
planLabel: data.label ?? data.tier,
|
|
}),
|
|
};
|
|
|
|
const enrichNotificationData = (type, data = {}) => (ENRICHERS[type] ? ENRICHERS[type](data) : data);
|
|
|
|
module.exports = { enrichNotificationData };
|