Files
starr-philproperties/models/notifications/notification_broadcast.mdl.js
T
kennethobsequio 1d12f04967 new commits
Signed-off-by: Kenneth Obsequio <k80308392@gmail.com>
2026-07-03 16:20:58 +08:00

55 lines
3.1 KiB
JavaScript

// models/notifications/notification_broadcast.mdl.js
const { DataTypes } = require("sequelize");
const sequelize = require("../../config/db.config");
const mdl_Users = require("../users/users.mdl");
const NotificationBroadcast = sequelize.define("NotificationBroadcast", {
// ─── Identity ─────────────────────────────────────────────────────────────
broadcast_id: { type: DataTypes.BIGINT, primaryKey: true, autoIncrement: true, label: "Broadcast ID", order: 0, hidden: true },
uuid: { type: DataTypes.UUID, defaultValue: DataTypes.UUIDV4, allowNull: false, unique: true, label: "UUID", order: 0, hidden: true },
// ─── Content ──────────────────────────────────────────────────────────────
title: { type: DataTypes.STRING(255), allowNull: false, label: "Title", order: 1 },
message: { type: DataTypes.TEXT, allowNull: false, label: "Message", order: 2 },
// ─── Targeting ────────────────────────────────────────────────────────────
target_type: {
type: DataTypes.ENUM("admin", "user", "both", "task_list", "course", "tier_plan"),
allowNull: false,
label: "Target", order: 3
},
// Holds a task list UUID, course UUID, or tier plan ID (stringified) — only
// set when target_type is 'task_list' / 'course' / 'tier_plan'.
target_id: { type: DataTypes.STRING(64), allowNull: true, label: "Target ID", order: 3.5 },
// ─── Lifecycle ────────────────────────────────────────────────────────────
status: {
type: DataTypes.ENUM("draft", "sent", "archived"),
allowNull: false,
defaultValue: "draft", label: "Status", order: 4
},
sent_at: { type: DataTypes.DATE, allowNull: true, label: "Sent At", order: 5 },
recipient_count: { type: DataTypes.INTEGER, allowNull: false, defaultValue: 0, label: "Recipients", order: 6 },
// ─── 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" },
}, {
tableName: "notification_broadcasts",
timestamps: true, // createdAt, updatedAt
paranoid: true,
indexes: [
{ fields: ["uuid"] },
{ fields: ["status"] },
{ fields: ["target_type"] },
{ fields: ["deletedAt"] },
],
});
NotificationBroadcast.belongsTo(mdl_Users, { as: "creator", foreignKey: "createdBy" });
NotificationBroadcast.belongsTo(mdl_Users, { as: "updater", foreignKey: "updatedBy" });
module.exports = NotificationBroadcast;