mirror of
https://github.com/rgrgogu/new_starr.git
synced 2026-09-27 00:12:54 +08:00
@@ -10,8 +10,9 @@ const CourseAssessment = sequelize.define("CourseAssessment", {
|
||||
passing_score: { type: DataTypes.INTEGER, defaultValue: 70 },
|
||||
time_limit_minutes: { type: DataTypes.INTEGER, allowNull: true }, // null = no limit
|
||||
max_questions: { type: DataTypes.INTEGER, allowNull: true }, // null = show all
|
||||
max_attempts: { type: DataTypes.INTEGER, defaultValue: 3 }, // failed attempts before cooldown
|
||||
cooldown_hours: { type: DataTypes.INTEGER, defaultValue: 24 }, // hours locked after hitting max_attempts
|
||||
max_attempts: { type: DataTypes.INTEGER, defaultValue: 3 }, // failed attempts before cooldown
|
||||
cooldown_hours: { type: DataTypes.INTEGER, defaultValue: 24 }, // hours locked after hitting max_attempts
|
||||
shuffle_questions: { type: DataTypes.BOOLEAN, defaultValue: false },
|
||||
createdBy: { type: DataTypes.BIGINT, allowNull: true },
|
||||
updatedBy: { type: DataTypes.BIGINT, allowNull: true },
|
||||
deletedBy: { type: DataTypes.BIGINT, allowNull: true },
|
||||
|
||||
@@ -14,10 +14,13 @@ const QuizOption = require("./quiz_option.mdl");
|
||||
const mdl_Users = require("../users/users.mdl");
|
||||
const QuizAttempt = require("./quiz_attempt.mdl");
|
||||
const AssessmentSession = require("./assessment_session.mdl");
|
||||
const QuizSession = require("./quiz_session.mdl");
|
||||
const mdl_Category = require("./categories.mdl");
|
||||
const Certificate = require("./certificate.mdl");
|
||||
const CourseInstructor = require("./course_instructor.mdl");
|
||||
const CourseReadingProgress = require("./course_reading_progress.mdl");
|
||||
const UnitReadingProgress = require("./unit_reading_progress.mdl");
|
||||
const LessonReadingProgress = require("./lesson_reading_progress.mdl");
|
||||
|
||||
// ── CourseReadingProgress ─────────────────────────────────────────────────────
|
||||
CourseReadingProgress.belongsTo(mdl_Users, { foreignKey: 'user_id', as: 'user' });
|
||||
@@ -25,6 +28,21 @@ CourseReadingProgress.belongsTo(Course, { foreignKey: 'course_id', as: 'cours
|
||||
mdl_Users.hasMany(CourseReadingProgress, { foreignKey: 'user_id', as: 'courseReadingProgress' });
|
||||
Course.hasMany(CourseReadingProgress, { foreignKey: 'course_id', as: 'readingProgress' });
|
||||
|
||||
// ── UnitReadingProgress ───────────────────────────────────────────────────────
|
||||
UnitReadingProgress.belongsTo(mdl_Users, { foreignKey: 'user_id', as: 'user' });
|
||||
UnitReadingProgress.belongsTo(Course, { foreignKey: 'course_id', as: 'course' });
|
||||
UnitReadingProgress.belongsTo(Unit, { foreignKey: 'unit_id', as: 'unit' });
|
||||
mdl_Users.hasMany(UnitReadingProgress, { foreignKey: 'user_id', as: 'unitReadingProgress' });
|
||||
Unit.hasMany(UnitReadingProgress, { foreignKey: 'unit_id', as: 'readingProgress' });
|
||||
|
||||
// ── LessonReadingProgress ─────────────────────────────────────────────────────
|
||||
LessonReadingProgress.belongsTo(mdl_Users, { foreignKey: 'user_id', as: 'user' });
|
||||
LessonReadingProgress.belongsTo(Course, { foreignKey: 'course_id', as: 'course' });
|
||||
LessonReadingProgress.belongsTo(Unit, { foreignKey: 'unit_id', as: 'unit' });
|
||||
LessonReadingProgress.belongsTo(Lesson, { foreignKey: 'lesson_id', as: 'lesson' });
|
||||
mdl_Users.hasMany(LessonReadingProgress, { foreignKey: 'user_id', as: 'lessonReadingProgress' });
|
||||
Lesson.hasMany(LessonReadingProgress, { foreignKey: 'lesson_id', as: 'readingProgress' });
|
||||
|
||||
// ── Course ────────────────────────────────────────────────────────────────────
|
||||
Course.belongsTo(mdl_Users, { as: "creator", foreignKey: "createdBy" });
|
||||
Course.belongsTo(mdl_Users, { as: "updater", foreignKey: "updatedBy" });
|
||||
@@ -85,13 +103,18 @@ AssessmentSession.belongsTo(CourseAssessment, { as: "assessment", foreignKey: "a
|
||||
AssessmentSession.belongsTo(mdl_Users, { as: "user", foreignKey: "user_id" });
|
||||
CourseAssessment.hasMany(AssessmentSession, { as: "sessions", foreignKey: "assessment_id" });
|
||||
|
||||
// ── QuizSession ───────────────────────────────────────────────────────────────
|
||||
QuizSession.belongsTo(UnitQuiz, { as: "quiz", foreignKey: "quiz_id" });
|
||||
QuizSession.belongsTo(mdl_Users, { as: "user", foreignKey: "user_id" });
|
||||
UnitQuiz.hasMany(QuizSession, { as: "sessions", foreignKey: "quiz_id" });
|
||||
|
||||
module.exports = {
|
||||
Course, CourseProductCategory,
|
||||
Unit, Lesson, LessonPage,
|
||||
CourseObjective, LessonObjective,
|
||||
CoursePrerequisite, CourseAssessment,
|
||||
UnitQuiz, QuizQuestion, QuizOption, QuizAttempt,
|
||||
AssessmentSession,
|
||||
AssessmentSession, QuizSession,
|
||||
mdl_Category, Certificate, CourseInstructor,
|
||||
CourseReadingProgress,
|
||||
CourseReadingProgress, UnitReadingProgress, LessonReadingProgress,
|
||||
};
|
||||
@@ -9,7 +9,7 @@ const Course = sequelize.define("Course", {
|
||||
course_code: { type: DataTypes.STRING(50), allowNull: true, unique: true, hidden: false, order: 1, filterable: true },
|
||||
order_index: { type: DataTypes.INTEGER, allowNull: false, defaultValue: 0, hidden: false, order: 7, filterable: false },
|
||||
level: { type: DataTypes.ENUM("beginner", "intermediate", "advanced"), allowNull: true, hidden: false, order: 3, filterable: true },
|
||||
subscription: { type: DataTypes.ENUM("free", "premium"), allowNull: false, defaultValue: "free", hidden: false, order: 4, filterable: true },
|
||||
subscription: { type: DataTypes.STRING(50), allowNull: false, defaultValue: "free", hidden: false, order: 4, filterable: true },
|
||||
duration_seconds: { type: DataTypes.INTEGER, allowNull: true, defaultValue: 0, hidden: false, order: 8, filterable: false },
|
||||
createdBy: { type: DataTypes.BIGINT, allowNull: true },
|
||||
updatedBy: { type: DataTypes.BIGINT, allowNull: true },
|
||||
|
||||
@@ -0,0 +1,85 @@
|
||||
/***********************************************************************************************************************************************************************
|
||||
* File Name: lesson_reading_progress.mdl.js
|
||||
* Type of Program: Model
|
||||
* Description: Tracks a user's reading progress at the lesson level.
|
||||
*
|
||||
* LessonReadingProgress — one row per (user, lesson).
|
||||
* UPSERT key: (user_id, lesson_id)
|
||||
* status is set directly by the caller ('in_progress' | 'completed').
|
||||
* last_accessed_at updated on every UPSERT.
|
||||
*
|
||||
* Author: Kenneth Obsequio (@lash0000)
|
||||
* Date Created: Jun. 26, 2026
|
||||
***********************************************************************************************************************************************************************/
|
||||
const { DataTypes } = require('sequelize');
|
||||
const sequelize = require('../../config/db.config');
|
||||
|
||||
const LessonReadingProgress = sequelize.define('LessonReadingProgress', {
|
||||
progress_id: {
|
||||
type: DataTypes.UUID,
|
||||
defaultValue: DataTypes.UUIDV4,
|
||||
primaryKey: true,
|
||||
},
|
||||
user_id: {
|
||||
type: DataTypes.BIGINT,
|
||||
allowNull: false,
|
||||
references: { model: 'users', key: 'user_id' },
|
||||
onDelete: 'CASCADE',
|
||||
},
|
||||
course_id: {
|
||||
type: DataTypes.BIGINT,
|
||||
allowNull: false,
|
||||
references: { model: 'courses', key: 'course_id' },
|
||||
onDelete: 'CASCADE',
|
||||
},
|
||||
unit_id: {
|
||||
type: DataTypes.BIGINT,
|
||||
allowNull: false,
|
||||
references: { model: 'units', key: 'unit_id' },
|
||||
onDelete: 'CASCADE',
|
||||
},
|
||||
lesson_id: {
|
||||
type: DataTypes.BIGINT,
|
||||
allowNull: false,
|
||||
references: { model: 'lessons', key: 'lesson_id' },
|
||||
onDelete: 'CASCADE',
|
||||
},
|
||||
status: {
|
||||
type: DataTypes.ENUM('in_progress', 'completed'),
|
||||
allowNull: false,
|
||||
defaultValue: 'in_progress',
|
||||
},
|
||||
completed_at: {
|
||||
type: DataTypes.DATE,
|
||||
allowNull: true,
|
||||
comment: 'Set when status flips to completed. Null while in_progress.',
|
||||
},
|
||||
last_accessed_at: {
|
||||
type: DataTypes.DATE,
|
||||
allowNull: false,
|
||||
defaultValue: DataTypes.NOW,
|
||||
comment: 'Updated on every UPSERT.',
|
||||
},
|
||||
|
||||
// ── Audit trails ────────────────────────────────────────────────────────
|
||||
createdBy: { type: DataTypes.BIGINT, allowNull: true },
|
||||
updatedBy: { type: DataTypes.BIGINT, allowNull: true },
|
||||
}, {
|
||||
tableName: 'lesson_reading_progress',
|
||||
timestamps: true,
|
||||
paranoid: false,
|
||||
indexes: [
|
||||
{
|
||||
unique: true,
|
||||
fields: ['user_id', 'lesson_id'],
|
||||
name: 'uq_lrp_user_lesson',
|
||||
},
|
||||
{ fields: ['user_id'], name: 'idx_lrp_user_id' },
|
||||
{ fields: ['course_id'], name: 'idx_lrp_course_id' },
|
||||
{ fields: ['unit_id'], name: 'idx_lrp_unit_id' },
|
||||
{ fields: ['lesson_id'], name: 'idx_lrp_lesson_id' },
|
||||
{ fields: ['status'], name: 'idx_lrp_status' },
|
||||
],
|
||||
});
|
||||
|
||||
module.exports = LessonReadingProgress;
|
||||
@@ -0,0 +1,20 @@
|
||||
const { DataTypes } = require("sequelize");
|
||||
const sequelize = require("../../config/db.config");
|
||||
|
||||
const QuizSession = sequelize.define("QuizSession", {
|
||||
session_id: { type: DataTypes.BIGINT, primaryKey: true, autoIncrement: true },
|
||||
uuid: { type: DataTypes.UUID, defaultValue: DataTypes.UUIDV4, unique: true },
|
||||
user_id: { type: DataTypes.BIGINT, allowNull: false },
|
||||
quiz_id: { type: DataTypes.BIGINT, allowNull: false },
|
||||
course_id: { type: DataTypes.BIGINT, allowNull: true },
|
||||
unit_id: { type: DataTypes.BIGINT, allowNull: true },
|
||||
status: { type: DataTypes.STRING(20), allowNull: false, defaultValue: 'in_progress' }, // 'in_progress' | 'submitted'
|
||||
draft_answers: { type: DataTypes.JSONB, allowNull: true, defaultValue: null },
|
||||
started_at: { type: DataTypes.DATE, allowNull: false, defaultValue: DataTypes.NOW },
|
||||
last_saved_at: { type: DataTypes.DATE, allowNull: true, defaultValue: null },
|
||||
}, {
|
||||
tableName: "quiz_sessions",
|
||||
timestamps: true,
|
||||
});
|
||||
|
||||
module.exports = QuizSession;
|
||||
@@ -6,9 +6,10 @@ const UnitQuiz = sequelize.define("UnitQuiz", {
|
||||
uuid: { type: DataTypes.UUID, defaultValue: DataTypes.UUIDV4, unique: true },
|
||||
unit_id: { type: DataTypes.BIGINT, allowNull: false, unique: true }, // one quiz per unit
|
||||
title: { type: DataTypes.STRING(255), allowNull: true },
|
||||
is_required: { type: DataTypes.BOOLEAN, defaultValue: false },
|
||||
passing_score: { type: DataTypes.INTEGER, defaultValue: 70 }, // percentage
|
||||
max_questions: { type: DataTypes.INTEGER, allowNull: true }, // null = show all
|
||||
is_required: { type: DataTypes.BOOLEAN, defaultValue: false },
|
||||
passing_score: { type: DataTypes.INTEGER, defaultValue: 70 }, // percentage
|
||||
max_questions: { type: DataTypes.INTEGER, allowNull: true }, // null = show all
|
||||
shuffle_questions: { type: DataTypes.BOOLEAN, defaultValue: false },
|
||||
createdBy: { type: DataTypes.BIGINT, allowNull: true },
|
||||
updatedBy: { type: DataTypes.BIGINT, allowNull: true },
|
||||
deletedBy: { type: DataTypes.BIGINT, allowNull: true },
|
||||
|
||||
@@ -0,0 +1,78 @@
|
||||
/***********************************************************************************************************************************************************************
|
||||
* File Name: unit_reading_progress.mdl.js
|
||||
* Type of Program: Model
|
||||
* Description: Tracks a user's reading progress at the unit level.
|
||||
*
|
||||
* UnitReadingProgress — one row per (user, unit).
|
||||
* UPSERT key: (user_id, unit_id)
|
||||
* status flips in_progress → completed when all sibling lessons are completed.
|
||||
* last_accessed_at updated on every UPSERT.
|
||||
*
|
||||
* Author: Kenneth Obsequio (@lash0000)
|
||||
* Date Created: Jun. 26, 2026
|
||||
***********************************************************************************************************************************************************************/
|
||||
const { DataTypes } = require('sequelize');
|
||||
const sequelize = require('../../config/db.config');
|
||||
|
||||
const UnitReadingProgress = sequelize.define('UnitReadingProgress', {
|
||||
progress_id: {
|
||||
type: DataTypes.UUID,
|
||||
defaultValue: DataTypes.UUIDV4,
|
||||
primaryKey: true,
|
||||
},
|
||||
user_id: {
|
||||
type: DataTypes.BIGINT,
|
||||
allowNull: false,
|
||||
references: { model: 'users', key: 'user_id' },
|
||||
onDelete: 'CASCADE',
|
||||
},
|
||||
course_id: {
|
||||
type: DataTypes.BIGINT,
|
||||
allowNull: false,
|
||||
references: { model: 'courses', key: 'course_id' },
|
||||
onDelete: 'CASCADE',
|
||||
},
|
||||
unit_id: {
|
||||
type: DataTypes.BIGINT,
|
||||
allowNull: false,
|
||||
references: { model: 'units', key: 'unit_id' },
|
||||
onDelete: 'CASCADE',
|
||||
},
|
||||
status: {
|
||||
type: DataTypes.ENUM('in_progress', 'completed'),
|
||||
allowNull: false,
|
||||
defaultValue: 'in_progress',
|
||||
},
|
||||
completed_at: {
|
||||
type: DataTypes.DATE,
|
||||
allowNull: true,
|
||||
comment: 'Set when status flips to completed. Null while in_progress.',
|
||||
},
|
||||
last_accessed_at: {
|
||||
type: DataTypes.DATE,
|
||||
allowNull: false,
|
||||
defaultValue: DataTypes.NOW,
|
||||
comment: 'Updated on every UPSERT.',
|
||||
},
|
||||
|
||||
// ── Audit trails ────────────────────────────────────────────────────────
|
||||
createdBy: { type: DataTypes.BIGINT, allowNull: true },
|
||||
updatedBy: { type: DataTypes.BIGINT, allowNull: true },
|
||||
}, {
|
||||
tableName: 'unit_reading_progress',
|
||||
timestamps: true,
|
||||
paranoid: false,
|
||||
indexes: [
|
||||
{
|
||||
unique: true,
|
||||
fields: ['user_id', 'unit_id'],
|
||||
name: 'uq_urp_user_unit',
|
||||
},
|
||||
{ fields: ['user_id'], name: 'idx_urp_user_id' },
|
||||
{ fields: ['course_id'], name: 'idx_urp_course_id' },
|
||||
{ fields: ['unit_id'], name: 'idx_urp_unit_id' },
|
||||
{ fields: ['status'], name: 'idx_urp_status' },
|
||||
],
|
||||
});
|
||||
|
||||
module.exports = UnitReadingProgress;
|
||||
@@ -0,0 +1,19 @@
|
||||
const { DataTypes } = require('sequelize');
|
||||
const sequelize = require('../../config/db.config');
|
||||
|
||||
const mdl_SystemBadges = sequelize.define('SystemBadge', {
|
||||
badge_id: { type: DataTypes.BIGINT, primaryKey: true, autoIncrement: true },
|
||||
key: { type: DataTypes.STRING(50), allowNull: false, unique: true, label: 'Badge Key' },
|
||||
asset_id: { type: DataTypes.BIGINT, allowNull: true, label: 'Asset' },
|
||||
label: { type: DataTypes.STRING(100), allowNull: false, label: 'Label' },
|
||||
description: { type: DataTypes.TEXT, allowNull: true, label: 'Description' },
|
||||
information: { type: DataTypes.TEXT, allowNull: true, label: 'Information' },
|
||||
active_from: { type: DataTypes.DATEONLY, allowNull: true, label: 'Active From' },
|
||||
active_until: { type: DataTypes.DATEONLY, allowNull: true, label: 'Active Until' },
|
||||
}, {
|
||||
tableName: 'system_badges',
|
||||
timestamps: true,
|
||||
paranoid: false,
|
||||
});
|
||||
|
||||
module.exports = mdl_SystemBadges;
|
||||
@@ -0,0 +1,14 @@
|
||||
const { DataTypes } = require('sequelize');
|
||||
const sequelize = require('../../config/db.config');
|
||||
|
||||
const mdl_PlanPolicies = sequelize.define('PlanPolicy', {
|
||||
policy_id: { type: DataTypes.BIGINT, primaryKey: true, autoIncrement: true },
|
||||
plan_id: { type: DataTypes.BIGINT, allowNull: false, unique: true },
|
||||
access_rules: { type: DataTypes.JSONB, allowNull: false, defaultValue: [], label: 'Access Rules' },
|
||||
}, {
|
||||
tableName: 'plan_policies',
|
||||
timestamps: true,
|
||||
paranoid: false,
|
||||
});
|
||||
|
||||
module.exports = mdl_PlanPolicies;
|
||||
@@ -1,15 +1,26 @@
|
||||
const mdl_Users = require('../users/users.mdl');
|
||||
const mdl_TierPlans = require('./tier_plans.mdl');
|
||||
const mdl_UserTiers = require('./user_tiers.mdl');
|
||||
const mdl_Payments = require('./payments.mdl');
|
||||
const mdl_PlanCourses = require('./plan_courses.mdl');
|
||||
const { Course } = require('../courses/courses.mdl'); // ← named export
|
||||
const mdl_Users = require('../users/users.mdl');
|
||||
const mdl_TierCategories = require('./tier_categories.mdl');
|
||||
const mdl_TierPlans = require('./tier_plans.mdl');
|
||||
const mdl_UserTiers = require('./user_tiers.mdl');
|
||||
const mdl_Payments = require('./payments.mdl');
|
||||
const mdl_PlanCourses = require('./plan_courses.mdl');
|
||||
const mdl_PlanPolicies = require('./plan_policies.mdl');
|
||||
const mdl_SystemBadges = require('../system_badges/system_badges.mdl');
|
||||
const Asset = require('../assets/assets.mdl');
|
||||
const { Course } = require('../courses/courses.mdl');
|
||||
|
||||
// ─── TierCategory ─────────────────────────────────────────────────────────────
|
||||
mdl_TierCategories.belongsTo(Asset, { foreignKey: 'badge_asset_id', as: 'badgeAsset' });
|
||||
mdl_TierCategories.hasMany(mdl_TierPlans, { foreignKey: 'tier_category_id', as: 'plans' });
|
||||
|
||||
// ─── TierPlans → TierCategory ─────────────────────────────────────────────────
|
||||
mdl_TierPlans.belongsTo(mdl_TierCategories, { foreignKey: 'tier_category_id', as: 'category' });
|
||||
|
||||
// ─── UserTiers ────────────────────────────────────────────────────────────────
|
||||
mdl_UserTiers.belongsTo(mdl_Users, { foreignKey: 'user_id', as: 'user' });
|
||||
mdl_UserTiers.belongsTo(mdl_Users, { foreignKey: 'granted_by', as: 'grantedByUser' });
|
||||
mdl_UserTiers.belongsTo(mdl_Users, { foreignKey: 'revoked_by', as: 'revokedByUser' });
|
||||
mdl_Users.hasMany(mdl_UserTiers, { foreignKey: 'user_id', as: 'tiers' });
|
||||
mdl_UserTiers.belongsTo(mdl_Users, { foreignKey: 'user_id', as: 'user' });
|
||||
mdl_UserTiers.belongsTo(mdl_Users, { foreignKey: 'granted_by', as: 'grantedByUser' });
|
||||
mdl_UserTiers.belongsTo(mdl_Users, { foreignKey: 'revoked_by', as: 'revokedByUser' });
|
||||
mdl_Users.hasMany(mdl_UserTiers, { foreignKey: 'user_id', as: 'tiers' });
|
||||
|
||||
// ─── Payments ─────────────────────────────────────────────────────────────────
|
||||
mdl_Payments.belongsTo(mdl_Users, { foreignKey: 'user_id', as: 'user' });
|
||||
@@ -23,17 +34,34 @@ mdl_TierPlans.belongsToMany(Course, {
|
||||
otherKey: 'course_id',
|
||||
as: 'courses',
|
||||
});
|
||||
|
||||
Course.belongsToMany(mdl_TierPlans, {
|
||||
through: mdl_PlanCourses,
|
||||
foreignKey: 'course_id',
|
||||
otherKey: 'plan_id',
|
||||
as: 'plans',
|
||||
});
|
||||
|
||||
mdl_PlanCourses.belongsTo(mdl_TierPlans, { foreignKey: 'plan_id', as: 'plan' });
|
||||
mdl_PlanCourses.belongsTo(Course, { foreignKey: 'course_id', as: 'course' });
|
||||
Course.hasOne(mdl_PlanCourses, { as: 'planCourse', foreignKey: 'course_id' });
|
||||
mdl_TierPlans.hasMany(mdl_PlanCourses, { as: 'planCourses', foreignKey: 'plan_id' });
|
||||
Course.hasOne(mdl_PlanCourses, { as: 'planCourse', foreignKey: 'course_id' });
|
||||
mdl_TierPlans.hasMany(mdl_PlanCourses, { as: 'planCourses', foreignKey: 'plan_id' });
|
||||
|
||||
module.exports = { mdl_TierPlans, mdl_UserTiers, mdl_Payments, mdl_PlanCourses };
|
||||
// ─── UserTier → Plan ──────────────────────────────────────────────────────────
|
||||
mdl_UserTiers.belongsTo(mdl_TierPlans, { foreignKey: 'plan_id', as: 'plan' });
|
||||
mdl_TierPlans.hasMany(mdl_UserTiers, { foreignKey: 'plan_id', as: 'userTiers' });
|
||||
|
||||
// ─── Plan ↔ Policy ────────────────────────────────────────────────────────────
|
||||
mdl_TierPlans.hasOne(mdl_PlanPolicies, { foreignKey: 'plan_id', as: 'policy' });
|
||||
mdl_PlanPolicies.belongsTo(mdl_TierPlans, { foreignKey: 'plan_id', as: 'plan' });
|
||||
|
||||
// ─── SystemBadge → Asset ─────────────────────────────────────────────────────
|
||||
mdl_SystemBadges.belongsTo(Asset, { foreignKey: 'asset_id', as: 'asset' });
|
||||
|
||||
module.exports = {
|
||||
mdl_TierCategories,
|
||||
mdl_TierPlans,
|
||||
mdl_UserTiers,
|
||||
mdl_Payments,
|
||||
mdl_PlanCourses,
|
||||
mdl_PlanPolicies,
|
||||
mdl_SystemBadges,
|
||||
};
|
||||
|
||||
@@ -0,0 +1,22 @@
|
||||
const { DataTypes } = require('sequelize');
|
||||
const sequelize = require('../../config/db.config');
|
||||
|
||||
const mdl_TierCategories = sequelize.define('TierCategory', {
|
||||
tier_category_id: { type: DataTypes.BIGINT, primaryKey: true, autoIncrement: true },
|
||||
slug: { type: DataTypes.STRING(50), allowNull: false, unique: true, label: 'Slug' },
|
||||
name: { type: DataTypes.STRING(100), allowNull: false, label: 'Name' },
|
||||
description: { type: DataTypes.TEXT, allowNull: true, label: 'Description' },
|
||||
rank: { type: DataTypes.INTEGER, allowNull: false, defaultValue: 0, label: 'Rank' },
|
||||
badge_asset_id: { type: DataTypes.BIGINT, allowNull: true, label: 'Badge Asset' },
|
||||
badge_icon: { type: DataTypes.STRING(50), allowNull: true, label: 'Badge Icon' },
|
||||
badge_label: { type: DataTypes.STRING(100), allowNull: true, label: 'Badge Label' },
|
||||
color: { type: DataTypes.STRING(30), allowNull: false, defaultValue: 'purple', label: 'Color' },
|
||||
is_default: { type: DataTypes.BOOLEAN, allowNull: false, defaultValue: false, label: 'Default' },
|
||||
is_active: { type: DataTypes.BOOLEAN, allowNull: false, defaultValue: true, label: 'Active' },
|
||||
}, {
|
||||
tableName: 'tier_categories',
|
||||
timestamps: true,
|
||||
paranoid: false,
|
||||
});
|
||||
|
||||
module.exports = mdl_TierCategories;
|
||||
@@ -10,8 +10,9 @@ const { DataTypes } = require('sequelize');
|
||||
const sequelize = require('../../config/db.config');
|
||||
|
||||
const mdl_TierPlans = sequelize.define('TierPlan', {
|
||||
plan_id: { type: DataTypes.BIGINT, primaryKey: true, autoIncrement: true, label: 'Plan ID' },
|
||||
tier: { type: DataTypes.ENUM('premium', 'exclusive'), allowNull: false, label: 'Tier' },
|
||||
plan_id: { type: DataTypes.BIGINT, primaryKey: true, autoIncrement: true, label: 'Plan ID' },
|
||||
tier_category_id: { type: DataTypes.BIGINT, allowNull: true, label: 'Tier Category' },
|
||||
tier: { type: DataTypes.STRING(50), allowNull: false, label: 'Tier' },
|
||||
label: { type: DataTypes.STRING(100), allowNull: false, label: 'Plan Label' },
|
||||
duration_days: { type: DataTypes.INTEGER, allowNull: false, label: 'Duration (Days)' },
|
||||
price: { type: DataTypes.DECIMAL(10, 2), allowNull: false, label: 'Price' },
|
||||
|
||||
@@ -12,11 +12,12 @@ const sequelize = require('../../config/db.config');
|
||||
const mdl_UserTiers = sequelize.define('UserTier', {
|
||||
tier_id: { type: DataTypes.BIGINT, primaryKey: true, autoIncrement: true, label: 'Tier ID' },
|
||||
user_id: { type: DataTypes.BIGINT, allowNull: false, label: 'User ID' },
|
||||
tier: { type: DataTypes.ENUM('free', 'premium', 'exclusive'), allowNull: false, defaultValue: 'free', label: 'Tier' },
|
||||
tier: { type: DataTypes.STRING(50), allowNull: false, defaultValue: 'free', label: 'Tier' },
|
||||
status: { type: DataTypes.ENUM('active', 'expired', 'revoked'), allowNull: false, defaultValue: 'active', label: 'Status' },
|
||||
starts_at: { type: DataTypes.DATE, allowNull: false, defaultValue: DataTypes.NOW, label: 'Starts At' },
|
||||
expires_at: { type: DataTypes.DATE, allowNull: true, label: 'Expires At' },
|
||||
|
||||
plan_id: { type: DataTypes.BIGINT, allowNull: true, label: 'Plan ID' },
|
||||
granted_by: { type: DataTypes.BIGINT, allowNull: true, label: 'Granted By' },
|
||||
revoked_by: { type: DataTypes.BIGINT, allowNull: true, label: 'Revoked By' },
|
||||
revoked_at: { type: DataTypes.DATE, allowNull: true, label: 'Revoked At' },
|
||||
|
||||
@@ -0,0 +1,41 @@
|
||||
/***********************************************************************************************************************************************************************
|
||||
* 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;
|
||||
@@ -1,5 +1,5 @@
|
||||
const excludeAttributes = [
|
||||
"password", "otp_code", "otp_expires_at", 'must_change_password', 'password_expires_at',
|
||||
"password", "otp_code", "otp_expires_at", 'must_change_password', 'password_expires_at', "needs_intro",
|
||||
"personal_info.name.given_name",
|
||||
"personal_info.name.middle_name",
|
||||
"personal_info.name.last_name",
|
||||
|
||||
@@ -43,6 +43,10 @@ const mdl_Users = sequelize.define('User', {
|
||||
*/
|
||||
personal_info: { type: DataTypes.JSONB, defaultValue: null, label: "Personal Info", order: 2 },
|
||||
|
||||
// ── Ban state ────────────────────────────────────────────────────────────────
|
||||
is_banned: { type: DataTypes.BOOLEAN, defaultValue: false, allowNull: false, label: "Banned" },
|
||||
ban_expires_at: { type: DataTypes.DATE, defaultValue: null, allowNull: true, label: "Ban Expires At" },
|
||||
|
||||
// ── Password policy ─────────────────────────────────────────────────────────
|
||||
must_change_password: { type: DataTypes.BOOLEAN, defaultValue: false, allowNull: false, label: "Must Change Password" },
|
||||
password_expires_at: { type: DataTypes.DATE, defaultValue: null, allowNull: true, label: "Password Expires At" },
|
||||
|
||||
Reference in New Issue
Block a user