mirror of
https://github.com/rgrgogu/new_starr.git
synced 2026-09-27 00:12:54 +08:00
@@ -0,0 +1,15 @@
|
||||
// models/notifications/cron_notification_setting.mdl.js
|
||||
const { DataTypes } = require("sequelize");
|
||||
const sequelize = require("../../config/db.config");
|
||||
|
||||
const CronNotificationSetting = sequelize.define("CronNotificationSetting", {
|
||||
job_name: { type: DataTypes.STRING(64), primaryKey: true, label: "Job" },
|
||||
enabled: { type: DataTypes.BOOLEAN, allowNull: false, defaultValue: true, label: "Enabled" },
|
||||
schedule: { type: DataTypes.STRING(20), allowNull: false, label: "Schedule" },
|
||||
updatedBy: { type: DataTypes.BIGINT, allowNull: true, label: "Modified By" },
|
||||
}, {
|
||||
tableName: "cron_notification_settings",
|
||||
timestamps: true,
|
||||
});
|
||||
|
||||
module.exports = CronNotificationSetting;
|
||||
@@ -0,0 +1,24 @@
|
||||
// models/notifications/notification_broadcast.attributes.js
|
||||
|
||||
// ─── Exclude sets ─────────────────────────────────────────────────────────────
|
||||
|
||||
const excludeAttributes = [];
|
||||
|
||||
// Admins see everything
|
||||
const adminExclude = [
|
||||
...excludeAttributes,
|
||||
];
|
||||
|
||||
// ─── JSONB schemas ──────────────────────────────────────────────────────────
|
||||
// No JSONB columns on this model.
|
||||
const jsonbSchemas = {};
|
||||
|
||||
// ─── Computed attributes ──────────────────────────────────────────────────────
|
||||
const computedAttributes = [];
|
||||
|
||||
module.exports = {
|
||||
excludeAttributes,
|
||||
adminExclude,
|
||||
jsonbSchemas,
|
||||
computedAttributes,
|
||||
};
|
||||
@@ -0,0 +1,54 @@
|
||||
// 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;
|
||||
Reference in New Issue
Block a user