mirror of
https://github.com/rgrgogu/new_starr.git
synced 2026-09-27 00:12:54 +08:00
@@ -1,38 +0,0 @@
|
||||
/***********************************************************************************************************************************************************************
|
||||
* File Name: email_broadcast.mdl.js
|
||||
* Type of Program: Model
|
||||
* Description: One "send this email template to this audience" job. The API
|
||||
* only ever creates this row + its email_broadcast_recipients
|
||||
* rows (see controllers/admin/email_broadcasts.controller.js) —
|
||||
* actual SMTP sending happens later, paced, in
|
||||
* cron/jobs/dispatch_email_broadcasts.cron.js.
|
||||
* Author: Kenneth Obsequio (@lash0000)
|
||||
* Date Created: Jul. 3, 2026
|
||||
***********************************************************************************************************************************************************************/
|
||||
const { DataTypes } = require('sequelize');
|
||||
const sequelize = require('../../config/db.config');
|
||||
const mdl_EmailTemplate = require('./email_templates.mdl');
|
||||
const mdl_Users = require('../users/users.mdl');
|
||||
|
||||
const mdl_EmailBroadcast = sequelize.define('EmailBroadcast', {
|
||||
email_broadcast_id: { type: DataTypes.BIGINT, primaryKey: true, autoIncrement: true, label: 'ID', hidden: true, order: 0 },
|
||||
email_template_id: { type: DataTypes.BIGINT, allowNull: false, label: 'Template', order: 1 },
|
||||
target_type: { type: DataTypes.ENUM('admin', 'user', 'both', 'task_list', 'course', 'tier_plan'), allowNull: false, label: 'Target', order: 2, filterable: true },
|
||||
target_id: { type: DataTypes.STRING(64), allowNull: true, label: 'Target ID', order: 3 },
|
||||
status: { type: DataTypes.ENUM('queued', 'sending', 'completed', 'canceled'), allowNull: false, defaultValue: 'queued', label: 'Status', order: 4, filterable: true },
|
||||
total_recipients: { type: DataTypes.INTEGER, allowNull: false, defaultValue: 0, label: 'Total', order: 5 },
|
||||
sent_count: { type: DataTypes.INTEGER, allowNull: false, defaultValue: 0, label: 'Sent', order: 6 },
|
||||
failed_count: { type: DataTypes.INTEGER, allowNull: false, defaultValue: 0, label: 'Failed', order: 7 },
|
||||
started_at: { type: DataTypes.DATE, allowNull: true, label: 'Started', order: 8 },
|
||||
completed_at: { type: DataTypes.DATE, allowNull: true, label: 'Completed', order: 9 },
|
||||
createdBy: { type: DataTypes.BIGINT, allowNull: true, label: 'Created By' },
|
||||
}, {
|
||||
tableName: 'email_broadcasts',
|
||||
timestamps: true,
|
||||
paranoid: false,
|
||||
});
|
||||
|
||||
mdl_EmailBroadcast.belongsTo(mdl_EmailTemplate, { as: 'template', foreignKey: 'email_template_id' });
|
||||
mdl_EmailBroadcast.belongsTo(mdl_Users, { as: 'creator', foreignKey: 'createdBy' });
|
||||
|
||||
module.exports = mdl_EmailBroadcast;
|
||||
@@ -1,33 +0,0 @@
|
||||
/***********************************************************************************************************************************************************************
|
||||
* File Name: email_broadcast_recipient.mdl.js
|
||||
* Type of Program: Model
|
||||
* Description: The outbox — one row per recipient of an email_broadcasts job.
|
||||
* `email` is snapshotted at enqueue time so a later change to the
|
||||
* user's account email doesn't affect an in-flight broadcast.
|
||||
* cron/jobs/dispatch_email_broadcasts.cron.js is the only writer
|
||||
* of `status`/`error`/`sent_at` after creation.
|
||||
* Author: Kenneth Obsequio (@lash0000)
|
||||
* Date Created: Jul. 3, 2026
|
||||
***********************************************************************************************************************************************************************/
|
||||
const { DataTypes } = require('sequelize');
|
||||
const sequelize = require('../../config/db.config');
|
||||
const mdl_EmailBroadcast = require('./email_broadcast.mdl');
|
||||
|
||||
const mdl_EmailBroadcastRecipient = sequelize.define('EmailBroadcastRecipient', {
|
||||
email_broadcast_recipient_id: { type: DataTypes.BIGINT, primaryKey: true, autoIncrement: true, label: 'ID', hidden: true, order: 0 },
|
||||
email_broadcast_id: { type: DataTypes.BIGINT, allowNull: false, label: 'Broadcast', order: 1 },
|
||||
user_id: { type: DataTypes.BIGINT, allowNull: true, label: 'User', order: 2 },
|
||||
email: { type: DataTypes.STRING(255), allowNull: false, label: 'Email', order: 3 },
|
||||
name: { type: DataTypes.STRING(255), allowNull: true, label: 'Name', order: 4 },
|
||||
status: { type: DataTypes.ENUM('pending', 'sent', 'failed'), allowNull: false, defaultValue: 'pending', label: 'Status', order: 5, filterable: true },
|
||||
error: { type: DataTypes.TEXT, allowNull: true, label: 'Error', order: 6 },
|
||||
sent_at: { type: DataTypes.DATE, allowNull: true, label: 'Sent At', order: 7 },
|
||||
}, {
|
||||
tableName: 'email_broadcast_recipients',
|
||||
timestamps: true,
|
||||
paranoid: false,
|
||||
});
|
||||
|
||||
mdl_EmailBroadcastRecipient.belongsTo(mdl_EmailBroadcast, { as: 'broadcast', foreignKey: 'email_broadcast_id' });
|
||||
|
||||
module.exports = mdl_EmailBroadcastRecipient;
|
||||
@@ -1,49 +0,0 @@
|
||||
/***********************************************************************************************************************************************************************
|
||||
* 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;
|
||||
Reference in New Issue
Block a user