Signed-off-by: Kenneth Obsequio <k80308392@gmail.com>
This commit is contained in:
2026-07-12 12:39:17 +08:00
parent 82ea9c77c4
commit ea3e82e54c
47 changed files with 1301 additions and 481 deletions
@@ -42,6 +42,33 @@ const AdminNotification = sequelize.define('AdminNotification', {
defaultValue: false,
},
// Named color key (utils/tierColors.js on the frontend) for the sticky banner.
color: {
type: DataTypes.STRING(20),
allowNull: false,
defaultValue: 'indigo',
},
// Denormalized copy of the source NotificationBroadcast's visibility
// window (see notificationVisibility.util.js) — null means unbounded.
start_date: {
type: DataTypes.DATE,
allowNull: true,
},
end_date: {
type: DataTypes.DATE,
allowNull: true,
},
// Links back to the source broadcast so editing it after send can
// propagate content changes into already-created rows (see
// notificationBroadcasts.controller.js#updateBroadcast). Null for
// notification types with no broadcast source.
broadcast_id: {
type: DataTypes.BIGINT,
allowNull: true,
},
data: {
type: DataTypes.JSONB,
allowNull: true,
@@ -15,6 +15,20 @@ const NotificationBroadcast = sequelize.define("NotificationBroadcast", {
// When set, the client's "view full content" dialog shows an "Open Link"
// action pointing here. When null, that dialog is plain text info only.
link_url: { type: DataTypes.STRING(2048), allowNull: true, label: "Link URL", order: 2.2 },
// Custom CTA button text shown right after the title in the sticky banner
// (e.g. "Shop now"). Falls back to "Open Link" when unset.
link_label: { type: DataTypes.STRING(60), allowNull: true, label: "Button Label", order: 2.3 },
// Named color key (see utils/tierColors.js on the frontend) driving the
// sticky banner's panel background/border — same registry rewards/tiers use.
color: { type: DataTypes.STRING(20), allowNull: false, defaultValue: 'indigo', label: "Color", order: 2.4 },
// Optional visibility window. Null start_date = show immediately once sent;
// null end_date = show indefinitely. Copied onto AdminNotification/
// UserNotification rows at send time so client reads can filter without
// joining back to this table (see sendBroadcast + notificationVisibility.util.js).
start_date: { type: DataTypes.DATE, allowNull: true, label: "Start Date", order: 2.7 },
end_date: { type: DataTypes.DATE, allowNull: true, label: "End Date", order: 2.8 },
// ─── Visibility ──────────────────────────────────────────────────────────
// Determines where a delivered announcement shows up for recipients.
@@ -1,46 +0,0 @@
/***********************************************************************************************************************************************************************
* File Name: notification_template.mdl.js
* Type of Program: Model
* Description: Admin-managed catalog of system-triggered notification wording
* (title + message). Mirrors models/email_templates/email_templates.mdl.js.
* `is_system` rows are the built-in types referenced by `type` from
* services/notificationTemplate.service.js's renderNotification()
* callers (cron jobs, controllers) — protected from deletion by the
* admin controller (no create/delete endpoint at all, since a new
* type needs a code call site before it means anything).
*
* Publish workflow: `title`/`message` are the LIVE content — the
* only columns renderNotification() ever reads. Editing a 'sent'
* template writes to `draft_title`/`draft_message` instead, leaving
* live content untouched until an admin explicitly publishes again
* (see controllers/admin/notification_templates.controller.js).
*
* Author: Kenneth Obsequio (@lash0000)
* Date Created: Jul. 3, 2026
***********************************************************************************************************************************************************************/
const { DataTypes } = require('sequelize');
const sequelize = require('../../config/db.config');
const mdl_NotificationTemplate = sequelize.define('NotificationTemplate', {
notification_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 },
// Written into the delivered admin_notifications/user_notifications row's own
// `type` column (e.g. 'task', 'course', 'announcement') — distinct from the
// lookup key above, since several lookup keys share the same delivered type.
notify_type: { type: DataTypes.STRING(64), allowNull: false, label: 'Notify Type', hidden: false, order: 2, filterable: true },
scope: { type: DataTypes.ENUM('admin', 'user', 'both'), allowNull: false, label: 'Scope', hidden: false, order: 3, filterable: true },
label: { type: DataTypes.STRING(150), allowNull: false, label: 'Label', hidden: false, order: 4, filterable: true },
status: { type: DataTypes.ENUM('draft', 'sent'), allowNull: false, defaultValue: 'draft', label: 'Status', hidden: false, order: 5, filterable: true },
title: { type: DataTypes.STRING(255), allowNull: true, label: 'Title', hidden: false, order: 6, filterable: false },
message: { type: DataTypes.TEXT, allowNull: true, label: 'Message', hidden: false, order: 7, filterable: false },
draft_title: { type: DataTypes.STRING(255), allowNull: true, label: 'Draft Title', hidden: false, order: 8, filterable: false },
draft_message: { type: DataTypes.TEXT, allowNull: true, label: 'Draft Message', hidden: false, order: 9, filterable: false },
last_sent_at: { type: DataTypes.DATE, allowNull: true, label: 'Last Published', hidden: false, order: 10, filterable: false },
is_system: { type: DataTypes.BOOLEAN, allowNull: false, defaultValue: false, label: 'System', hidden: false, order: 11, filterable: true },
}, {
tableName: 'notification_templates',
timestamps: true,
paranoid: false,
});
module.exports = mdl_NotificationTemplate;
@@ -0,0 +1,22 @@
// models/notifications/sticky_banner_setting.mdl.js
//
// Singleton (always id=1) — one shared banner image shown alongside every
// currently-active sticky announcement, not one image per announcement. Set
// from the Announcements list page (see admin/notificationBroadcasts.controller.js's
// getStickyBannerSetting/updateStickyBannerSetting).
const { DataTypes } = require("sequelize");
const sequelize = require("../../config/db.config");
const mdl_Assets = require("../assets/assets.mdl");
const StickyBannerSetting = sequelize.define("StickyBannerSetting", {
id: { type: DataTypes.SMALLINT, primaryKey: true, defaultValue: 1 },
image_asset_id: { type: DataTypes.BIGINT, allowNull: true },
updatedBy: { type: DataTypes.BIGINT, allowNull: true },
}, {
tableName: "sticky_banner_settings",
timestamps: true,
});
StickyBannerSetting.belongsTo(mdl_Assets, { as: "image", foreignKey: "image_asset_id" });
module.exports = StickyBannerSetting;
@@ -48,6 +48,33 @@ const UserNotification = sequelize.define('UserNotification', {
defaultValue: false,
},
// Named color key (utils/tierColors.js on the frontend) for the sticky banner.
color: {
type: DataTypes.STRING(20),
allowNull: false,
defaultValue: 'indigo',
},
// Denormalized copy of the source NotificationBroadcast's visibility
// window (see notificationVisibility.util.js) — null means unbounded.
start_date: {
type: DataTypes.DATE,
allowNull: true,
},
end_date: {
type: DataTypes.DATE,
allowNull: true,
},
// Links back to the source broadcast so editing it after send can
// propagate content changes into already-created rows (see
// notificationBroadcasts.controller.js#updateBroadcast). Null for
// notification types with no broadcast source.
broadcast_id: {
type: DataTypes.BIGINT,
allowNull: true,
},
data: {
type: DataTypes.JSONB,
allowNull: true,