chore: relocate backend into apps/api ahead of monorepo merge
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,115 @@
|
||||
/***********************************************************************************************************************************************************************
|
||||
* File Name : user_notification.mdl.js
|
||||
* Type : Sequelize Model
|
||||
* Description : Client-facing per-user notifications (achievement unlocked,
|
||||
* task events, etc.). Scoped to a single user_id — each row
|
||||
* is private to the user it belongs to.
|
||||
*
|
||||
* Author: Kenneth Obsequio (@lash0000)
|
||||
* Date Created: Jun. 19, 2026
|
||||
***********************************************************************************************************************************************************************/
|
||||
const { DataTypes } = require('sequelize');
|
||||
const sequelize = require('../../config/db.config');
|
||||
const mdl_Assets = require('../assets/assets.mdl');
|
||||
|
||||
const UserNotification = sequelize.define('UserNotification', {
|
||||
notification_id: {
|
||||
type: DataTypes.BIGINT,
|
||||
autoIncrement: true,
|
||||
primaryKey: true,
|
||||
},
|
||||
user_id: {
|
||||
type: DataTypes.BIGINT,
|
||||
allowNull: false,
|
||||
},
|
||||
type: {
|
||||
type: DataTypes.STRING(64),
|
||||
allowNull: false,
|
||||
},
|
||||
title: {
|
||||
type: DataTypes.STRING(255),
|
||||
allowNull: false,
|
||||
},
|
||||
message: {
|
||||
type: DataTypes.TEXT,
|
||||
allowNull: false,
|
||||
},
|
||||
|
||||
// Controls where this notification is rendered.
|
||||
// - show_in_notifications: appears in the /notifications list + bell badge.
|
||||
// - show_in_sticky: appears in the fixed "sticky announcement" banner.
|
||||
show_in_notifications: {
|
||||
type: DataTypes.BOOLEAN,
|
||||
allowNull: false,
|
||||
defaultValue: true,
|
||||
},
|
||||
show_in_sticky: {
|
||||
type: DataTypes.BOOLEAN,
|
||||
allowNull: false,
|
||||
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 per-alert
|
||||
// layout image (see notification_broadcast.mdl.js) — null when the
|
||||
// alert has none.
|
||||
image_asset_id: {
|
||||
type: DataTypes.BIGINT,
|
||||
allowNull: true,
|
||||
},
|
||||
|
||||
// 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,
|
||||
defaultValue: null,
|
||||
},
|
||||
seen: {
|
||||
type: DataTypes.BOOLEAN,
|
||||
allowNull: false,
|
||||
defaultValue: false,
|
||||
},
|
||||
seen_at: {
|
||||
type: DataTypes.DATE,
|
||||
allowNull: true,
|
||||
defaultValue: null,
|
||||
},
|
||||
}, {
|
||||
tableName: 'user_notifications',
|
||||
timestamps: true,
|
||||
indexes: [
|
||||
{ fields: ['user_id'], name: 'idx_un_user_id' },
|
||||
{ fields: ['user_id', 'seen'], name: 'idx_un_seen' },
|
||||
{ fields: ['type'], name: 'idx_un_type' },
|
||||
{ fields: ['createdAt'], name: 'idx_un_created_at' },
|
||||
],
|
||||
});
|
||||
|
||||
UserNotification.belongsTo(mdl_Assets, { as: "image", foreignKey: "image_asset_id" });
|
||||
|
||||
module.exports = UserNotification;
|
||||
Reference in New Issue
Block a user