mirror of
https://github.com/rgrgogu/new_starr.git
synced 2026-09-27 00:12:54 +08:00
50 lines
4.1 KiB
JavaScript
50 lines
4.1 KiB
JavaScript
/***********************************************************************************************************************************************************************
|
|
* File Name: email_templates.mdl.js
|
|
* Type of Program: Model
|
|
* Description: Admin-managed catalog of email templates (subject + HTML body).
|
|
* Replaces the old static emailTemplates map in data/email_body.data.js.
|
|
* `is_system` rows are the built-in types referenced by name in
|
|
* services/email.service.js's sendEmail() callers — protected
|
|
* from deletion/type-rename by the admin controller. The outer
|
|
* layout (header/footer/signature) is NOT stored here — it stays
|
|
* fixed in services/email.service.js and is never admin-editable.
|
|
*
|
|
* Publish workflow: `subject`/`html_body` are the LIVE content —
|
|
* the only columns services/email.service.js's sendEmail() ever
|
|
* reads. Editing a 'sent' template writes to `draft_subject`/
|
|
* `draft_html_body` instead, leaving live content (and therefore
|
|
* real outgoing mail) untouched until an admin explicitly
|
|
* publishes again (see controllers/admin/email_templates.controller.js).
|
|
*
|
|
* Author: Kenneth Obsequio (@lash0000)
|
|
* Date Created: Jul. 3, 2026
|
|
***********************************************************************************************************************************************************************/
|
|
const { DataTypes } = require('sequelize');
|
|
const sequelize = require('../../config/db.config');
|
|
|
|
const mdl_EmailTemplate = sequelize.define('EmailTemplate', {
|
|
email_template_id: { type: DataTypes.BIGINT, primaryKey: true, autoIncrement: true, label: 'ID', hidden: true, order: 0 },
|
|
type: { type: DataTypes.STRING(100), allowNull: false, unique: true, label: 'Type', hidden: false, order: 1, filterable: true },
|
|
label: { type: DataTypes.STRING(150), allowNull: false, label: 'Label', hidden: false, order: 2, filterable: true },
|
|
category: { type: DataTypes.ENUM('announcement', 'advertisement', 'system', 'other'), allowNull: false, defaultValue: 'other', label: 'Category', hidden: false, order: 3, filterable: true },
|
|
status: { type: DataTypes.ENUM('draft', 'sent'), allowNull: false, defaultValue: 'draft', label: 'Status', hidden: false, order: 4, filterable: true },
|
|
subject: { type: DataTypes.STRING(255), allowNull: true, label: 'Subject', hidden: false, order: 5, filterable: false },
|
|
html_body: { type: DataTypes.TEXT, allowNull: true, label: 'HTML Body', hidden: false, order: 6, filterable: false },
|
|
// Markdown source for the live/draft HTML above — editor convenience only,
|
|
// never read by services/email.service.js. Null for templates authored
|
|
// before Markdown support (including all 8 system templates), which keep
|
|
// editing html_body/draft_html_body directly.
|
|
body_markdown: { type: DataTypes.TEXT, allowNull: true, label: 'Body (Markdown)', hidden: false, order: 6.5, filterable: false },
|
|
draft_subject: { type: DataTypes.STRING(255), allowNull: true, label: 'Draft Subject', hidden: false, order: 7, filterable: false },
|
|
draft_html_body: { type: DataTypes.TEXT, allowNull: true, label: 'Draft Body', hidden: false, order: 8, filterable: false },
|
|
draft_body_markdown: { type: DataTypes.TEXT, allowNull: true, label: 'Draft Body (Markdown)', hidden: false, order: 8.5, filterable: false },
|
|
last_sent_at: { type: DataTypes.DATE, allowNull: true, label: 'Last Sent', hidden: false, order: 9, filterable: false },
|
|
is_system: { type: DataTypes.BOOLEAN, allowNull: false, defaultValue: false, label: 'System', hidden: false, order: 10, filterable: true },
|
|
}, {
|
|
tableName: 'email_templates',
|
|
timestamps: true,
|
|
paranoid: false,
|
|
});
|
|
|
|
module.exports = mdl_EmailTemplate;
|