mirror of
https://github.com/rgrgogu/new_starr.git
synced 2026-09-27 00:12:54 +08:00
42 lines
2.4 KiB
JavaScript
42 lines
2.4 KiB
JavaScript
/***********************************************************************************************************************************************************************
|
|
* File Name: user_bans.mdl.js
|
|
* Type of Program: Model
|
|
* Description: Sequelize model for the `user_bans` table.
|
|
* Stores ban/unban audit records for policy enforcement actions.
|
|
* Distinct from deactivation (account lifecycle) — bans track WHY,
|
|
* WHO banned, duration, and lift history.
|
|
* Author: Kenneth Obsequio
|
|
* Date Created: Jun. 27, 2026
|
|
***********************************************************************************************************************************************************************/
|
|
const { DataTypes } = require('sequelize');
|
|
const sequelize = require('../../config/db.config');
|
|
const mdl_Users = require('./users.mdl');
|
|
|
|
const mdl_UserBans = sequelize.define('UserBan', {
|
|
ban_id: { type: DataTypes.BIGINT, primaryKey: true, autoIncrement: true },
|
|
user_id: { type: DataTypes.BIGINT, allowNull: false, references: { model: mdl_Users, key: 'user_id' } },
|
|
banned_by: { type: DataTypes.BIGINT, allowNull: false, references: { model: mdl_Users, key: 'user_id' } },
|
|
|
|
reason: { type: DataTypes.TEXT, allowNull: false },
|
|
ban_type: { type: DataTypes.ENUM('temporary', 'permanent'), allowNull: false },
|
|
|
|
banned_at: { type: DataTypes.DATE, allowNull: false, defaultValue: DataTypes.NOW },
|
|
expires_at: { type: DataTypes.DATE, allowNull: true },
|
|
|
|
is_lifted: { type: DataTypes.BOOLEAN, allowNull: false, defaultValue: false },
|
|
lifted_at: { type: DataTypes.DATE, allowNull: true },
|
|
lifted_by: { type: DataTypes.BIGINT, allowNull: true, references: { model: mdl_Users, key: 'user_id' } },
|
|
lift_reason: { type: DataTypes.TEXT, allowNull: true },
|
|
}, {
|
|
tableName: 'user_bans',
|
|
timestamps: true,
|
|
});
|
|
|
|
// ─── Associations ──────────────────────────────────────────────────────────────
|
|
mdl_UserBans.belongsTo(mdl_Users, { as: 'user', foreignKey: 'user_id' });
|
|
mdl_UserBans.belongsTo(mdl_Users, { as: 'banner', foreignKey: 'banned_by' });
|
|
mdl_UserBans.belongsTo(mdl_Users, { as: 'lifter', foreignKey: 'lifted_by' });
|
|
mdl_Users.hasMany(mdl_UserBans, { as: 'bans', foreignKey: 'user_id' });
|
|
|
|
module.exports = mdl_UserBans;
|