This commit is contained in:
rgrgogu
2026-05-05 23:18:47 +08:00
parent 5aeb959e92
commit a8f10a25d7
38 changed files with 5992 additions and 2 deletions
+59
View File
@@ -0,0 +1,59 @@
/***********************************************************************************************************************************************************************
* File Name: users.mdl.js
* Type of Program: Model
* Description: Sequelize model for the `users` table.
* Stores authentication credentials, account flags, registration type,
* role/account type, and a flexible JSONB personal_info column.
* Author: rgrgogu
* Date Created: Oct. 6, 2025
***********************************************************************************************************************************************************************
* Change History:
* DATE AUTHOR LOG DESCRIPTION
* Oct. 6, 2025 rgrgogu 001 Initial creation - STAR Phase 1
***********************************************************************************************************************************************************************/
const { DataTypes } = require('sequelize');
const sequelize = require('../../config/db.config');
const mdl_Users = sequelize.define('User', {
user_id: { type: DataTypes.BIGINT, primaryKey: true, autoIncrement: true, label: "User ID" },
email: { type: DataTypes.STRING(255), allowNull: false, unique: true, label: "Email Address", validate: { isEmail: true } },
password: { type: DataTypes.TEXT, label: "Password" },
is_active: { type: DataTypes.BOOLEAN, defaultValue: true, label: "Active" },
is_verified: { type: DataTypes.BOOLEAN, defaultValue: false, label: "Verified" },
reg_type: { type: DataTypes.ENUM('system', 'google'), defaultValue: 'system', label: "Registration Type" },
/**
* acc_type drives RBAC:
* - "user" → Client endpoints only
* - "staff" → Client + Staff endpoints
* - "admin" → All endpoints
*/
acc_type: { type: DataTypes.ENUM('user', 'staff', 'admin'), defaultValue: 'user', label: "Account Type" },
/**
* personal_info JSONB structure:
* {
* name: { given_name, middle_name, last_name, extension_name, full_name },
* occupation: string,
* addresses: [{ street, city, state, zip, country, address_type, full_address }],
* phone_number: [{ number, country_code, phone_type, full_number }],
* date_of_birth: date,
* avatar: { mime_type, name, size, url, uuid },
* album: [{ uuid, file_url, original_name, uploaded_at, order_index }]
* }
*/
personal_info: { type: DataTypes.JSONB, defaultValue: null, label: "Personal Info" },
// OTP fields (stored temporarily during verification flow)
otp_code: { type: DataTypes.STRING(6), allowNull: true, label: "OTP Code" },
otp_expires_at: { type: DataTypes.DATE, allowNull: true, label: "OTP Expires At" },
// ── 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: 'users',
timestamps: true,
paranoid: true, // enables soft delete — sets deleted_at instead of DELETE
});
module.exports = mdl_Users;