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
@@ -33,6 +33,10 @@ const Advertisement = sequelize.define("Advertisement", {
},
// ─── Content ──────────────────────────────────────────────────────────────
// "image" = image only, "content" = badge/headline/description/CTAs alongside
// the image — an explicit admin choice made in the creation wizard, decoupled
// from placement/format.
content_mode: { type: DataTypes.ENUM("image", "content"), allowNull: false, defaultValue: "image", label: "Content Mode", order: 3.5 },
badge_label: { type: DataTypes.STRING(100), label: "Badge Label", order: 4 },
headline: { type: DataTypes.STRING(255), label: "Headline", order: 5 },
description: { type: DataTypes.TEXT, label: "Description", order: 6 },
@@ -45,6 +49,15 @@ const Advertisement = sequelize.define("Advertisement", {
// [{ label, link }, ...] — 0-2 entries depending on type
ctas: { type: DataTypes.JSONB, allowNull: false, defaultValue: [], label: "CTAs", order: 7 },
// Where the ad as a whole links to when clicked with no CTA of its own
// (banners/full-image ads have no CTA row) — takes priority over landing_page.
redirect_link: { type: DataTypes.STRING(512), allowNull: true, label: "Redirect Link", order: 7.5 },
// Internally-authored landing page { title, description, body, links: [{label, link}] }
// used as the click-through destination when redirect_link is empty — see
// GET /api/client/advertisements/uuid/:uuid and the /ads/:uuid client route.
landing_page: { type: DataTypes.JSONB, allowNull: true, label: "Landing Page", order: 0, hidden: true },
// ─── Scheduling ───────────────────────────────────────────────────────────
start_date: { type: DataTypes.DATE, label: "Start Date", order: 8 },
end_date: { type: DataTypes.DATE, label: "End Date", order: 9 },
@@ -12,19 +12,10 @@
// in controllers/admin/advertisements.controller.js) — type is never accepted
// from the client once a placement is set.
// TODO(ads-1): Re-categorize placements — Hero -> Dashboard, Banner -> Tier Plans.
// Remove the "popup" and "sidebar" formats entirely (dashboard.popup,
// course_details.sidebar). Keep in sync with the frontend mirror at
// new_starr_app/src/data/placement.data.js. This also feeds the Step 1
// "Placement" picker in the Add Advertisement wizard (TODO(ads-6)), which
// should only offer Dashboard / Tier Plans / Course Details.
const PLACEMENTS = [
{ key: "dashboard.hero", format: "hero", page: "dashboard", pageLabel: "Dashboard", slotLabel: "Hero (top of page)" },
{ key: "dashboard.popup", format: "popup", page: "dashboard", pageLabel: "Dashboard", slotLabel: "Popup (on load)" },
{ key: "course_list.banner", format: "banner", page: "course_list", pageLabel: "Courses", slotLabel: "Banner (above course grid)" },
{ key: "tier_plans.banner", format: "banner", page: "tier_plans", pageLabel: "Tier Plans", slotLabel: "Banner (above plan cards)" },
{ key: "course_details.banner", format: "banner", page: "course_details", pageLabel: "Course Details", slotLabel: "Banner (below hero)" },
{ key: "course_details.sidebar", format: "sidebar", page: "course_details", pageLabel: "Course Details", slotLabel: "Sidebar (beside course content)" },
{ key: "plans.banner", format: "banner", page: "plans", pageLabel: "Plans", slotLabel: "Banner (above plan cards)" },
];
const PLACEMENT_MAP = Object.fromEntries(PLACEMENTS.map((p) => [p.key, p]));
+5 -5
View File
@@ -11,11 +11,11 @@ const Asset = sequelize.define("Asset", {
// ─── File info ────────────────────────────────────────────────────────────
original_name: { type: DataTypes.STRING(255), allowNull: false, label: "Original Name", order: 0, hidden: true },
display_name: { type: DataTypes.STRING(255), allowNull: false, label: "Name", order: 0 },
display_name: { type: DataTypes.STRING(255), allowNull: false, label: "Name", order: 0, filterable: true },
file_url: { type: DataTypes.STRING(512), allowNull: false, label: "File URL", order: 0, hidden: true },
file_size: { type: DataTypes.BIGINT, allowNull: false, label: "File Size", order: 0, hidden: true },
mime_type: { type: DataTypes.STRING(100), allowNull: false, label: "MIME Type", order: 0, hidden: true },
extension: { type: DataTypes.STRING(20), label: "File Type", order: 0 },
extension: { type: DataTypes.STRING(20), label: "File Type", order: 0, filterable: true },
checksum: { type: DataTypes.STRING(64), label: "Checksum", order: 0, hidden: true },
// ─── Classification ───────────────────────────────────────────────────────
@@ -57,9 +57,9 @@ const Asset = sequelize.define("Asset", {
},
// ── Audit trails ────────────────────────────────────────────────────────────
createdBy: { type: DataTypes.BIGINT, allowNull: true, label: "Created By" },
updatedBy: { type: DataTypes.BIGINT, allowNull: true, label: "Modified By" },
deletedBy: { type: DataTypes.BIGINT, allowNull: true, label: "Deleted By" },
createdBy: { type: DataTypes.BIGINT, allowNull: true, label: "Created By", filterable: true },
updatedBy: { type: DataTypes.BIGINT, allowNull: true, label: "Modified By", filterable: true },
deletedBy: { type: DataTypes.BIGINT, allowNull: true, label: "Deleted By", filterable: true },
}, {
tableName: "assets",
timestamps: true, // createdAt, updatedAt
@@ -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,