client and some admin new

Signed-off-by: Kenneth Obsequio <k80308392@gmail.com>
This commit is contained in:
2026-08-05 04:32:43 +08:00
parent 8922f7f2f4
commit 0c7f5ccd0f
33 changed files with 937 additions and 770 deletions
+5 -3
View File
@@ -33,9 +33,11 @@ const Advertisement = sequelize.define("Advertisement", {
},
// ─── Content ──────────────────────────────────────────────────────────────
// "image" = image only, "content" = badge/headline/description/CTAs alongside
// the image — an explicit admin choice made in the creation wizard, decoupled
// from placement/format.
// Every ad is now created/edited as "content" (badge/headline/description/
// image/link all mandatory) — applyAdvertisementFields on the backend fixes
// this server-side rather than accepting it from the client. "image" is
// legacy-only, left on rows created before the Image Only / Text with Image
// toggle was removed, until they're next edited.
content_mode: { type: DataTypes.ENUM("image", "content"), allowNull: false, defaultValue: "image", label: "Content Mode", order: 3.5 },
// Up to 2 outline-badge chips shown alongside the headline — see MAX_BADGE_LABELS.
badge_labels: { type: DataTypes.JSONB, allowNull: false, defaultValue: [], label: "Badge Labels", order: 4 },
+7 -1
View File
@@ -2,7 +2,13 @@
* File Name: plan_courses.mdl.js
* Type of Program: Model
* Description: Junction table — links courses to a specific tier plan.
* UNIQUE on course_id enforces one course belongs to one plan only.
* Composite UNIQUE on (plan_id, course_id) only prevents adding
* the same course twice to the same plan — a course may belong
* to many plans simultaneously (Tier Plans v2, silent duplication
* across bundles is intentional; see admin/tiers.controller.js).
* Bundling/display only, not an access-control mechanism — see
* controllers/client/courses.controller.js (hasItemGrant) /
* user_tier_grants for entitlement.
* Author: Kenneth Obsequio (@lash0000)
* Date Created: Jun. 6, 2026
***********************************************************************************************************************************************************************/
+5 -2
View File
@@ -2,9 +2,12 @@
* File Name: plan_lessons.mdl.js
* Type of Program: Model
* Description: Junction table — links standalone Lessons to a specific tier plan.
* UNIQUE on lesson_id enforces one lesson belongs to one plan only.
* Composite UNIQUE on (plan_id, lesson_id) only prevents adding
* the same lesson twice to the same plan — a lesson may belong
* to many plans simultaneously (Tier Plans v2, silent duplication
* across bundles is intentional; see admin/tiers.controller.js).
* Mirrors plan_courses.mdl.js — bundling/display only, not an
* access-control mechanism (see canAccessLesson).
* access-control mechanism (see canAccessLesson / user_tier_grants).
* Author: Kenneth Obsequio (@lash0000)
* Date Created: Aug. 1, 2026
***********************************************************************************************************************************************************************/
-14
View File
@@ -1,14 +0,0 @@
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;
+5 -2
View File
@@ -2,9 +2,12 @@
* File Name: plan_units.mdl.js
* Type of Program: Model
* Description: Junction table — links standalone Units to a specific tier plan.
* UNIQUE on unit_id enforces one unit belongs to one plan only.
* Composite UNIQUE on (plan_id, unit_id) only prevents adding the
* same unit twice to the same plan — a unit may belong to many
* plans simultaneously (Tier Plans v2, silent duplication across
* bundles is intentional; see admin/tiers.controller.js).
* Mirrors plan_courses.mdl.js — bundling/display only, not an
* access-control mechanism (see canAccessUnit).
* access-control mechanism (see canAccessUnit / user_tier_grants).
* Author: Kenneth Obsequio (@lash0000)
* Date Created: Aug. 1, 2026
***********************************************************************************************************************************************************************/
+10 -8
View File
@@ -6,7 +6,7 @@ const mdl_Payments = require('./payments.mdl');
const mdl_PlanCourses = require('./plan_courses.mdl');
const mdl_PlanUnits = require('./plan_units.mdl');
const mdl_PlanLessons = require('./plan_lessons.mdl');
const mdl_PlanPolicies = require('./plan_policies.mdl');
const mdl_UserTierGrants = require('./user_tier_grants.mdl');
const mdl_SystemBadges = require('../system_badges/system_badges.mdl');
const Asset = require('../assets/assets.mdl');
const { Course } = require('../courses/courses.mdl');
@@ -46,7 +46,7 @@ Course.belongsToMany(mdl_TierPlans, {
});
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' });
Course.hasMany(mdl_PlanCourses, { as: 'planCourses', foreignKey: 'course_id' });
mdl_TierPlans.hasMany(mdl_PlanCourses, { as: 'planCourses', foreignKey: 'plan_id' });
// ─── Plan ↔ Units ─────────────────────────────────────────────────────────────
@@ -64,7 +64,7 @@ Unit.belongsToMany(mdl_TierPlans, {
});
mdl_PlanUnits.belongsTo(mdl_TierPlans, { foreignKey: 'plan_id', as: 'plan' });
mdl_PlanUnits.belongsTo(Unit, { foreignKey: 'unit_id', as: 'unit' });
Unit.hasOne(mdl_PlanUnits, { as: 'planUnit', foreignKey: 'unit_id' });
Unit.hasMany(mdl_PlanUnits, { as: 'planUnits', foreignKey: 'unit_id' });
mdl_TierPlans.hasMany(mdl_PlanUnits, { as: 'planUnits', foreignKey: 'plan_id' });
// ─── Plan ↔ Lessons ───────────────────────────────────────────────────────────
@@ -82,16 +82,18 @@ Lesson.belongsToMany(mdl_TierPlans, {
});
mdl_PlanLessons.belongsTo(mdl_TierPlans, { foreignKey: 'plan_id', as: 'plan' });
mdl_PlanLessons.belongsTo(Lesson, { foreignKey: 'lesson_id', as: 'lesson' });
Lesson.hasOne(mdl_PlanLessons, { as: 'planLesson', foreignKey: 'lesson_id' });
Lesson.hasMany(mdl_PlanLessons, { as: 'planLessons', foreignKey: 'lesson_id' });
mdl_TierPlans.hasMany(mdl_PlanLessons, { as: 'planLessons', foreignKey: 'plan_id' });
// ─── 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' });
// ─── UserTier → UserTierGrants (item-specific entitlement snapshot) ──────────
mdl_UserTiers.hasMany(mdl_UserTierGrants, { foreignKey: 'user_tier_id', as: 'grants' });
mdl_UserTierGrants.belongsTo(mdl_UserTiers, { foreignKey: 'user_tier_id', as: 'userTier' });
mdl_UserTierGrants.belongsTo(mdl_Users, { foreignKey: 'user_id', as: 'user' });
mdl_UserTierGrants.belongsTo(mdl_TierPlans, { foreignKey: 'plan_id', as: 'plan' });
// ─── SystemBadge → Asset ─────────────────────────────────────────────────────
mdl_SystemBadges.belongsTo(Asset, { foreignKey: 'asset_id', as: 'asset' });
@@ -104,6 +106,6 @@ module.exports = {
mdl_PlanCourses,
mdl_PlanUnits,
mdl_PlanLessons,
mdl_PlanPolicies,
mdl_SystemBadges,
mdl_UserTierGrants,
};
+1
View File
@@ -21,6 +21,7 @@ const mdl_TierPlans = sequelize.define('TierPlan', {
price: { type: DataTypes.DECIMAL(10, 2), allowNull: false, label: 'Price' },
currency: { type: DataTypes.CHAR(3), allowNull: false, defaultValue: 'USD', label: 'Currency' },
is_active: { type: DataTypes.BOOLEAN, allowNull: false, defaultValue: true, label: 'Active' },
status: { type: DataTypes.ENUM('draft', 'published'), allowNull: false, defaultValue: 'draft', label: 'Status', hidden: false, filterable: true },
createdBy: { type: DataTypes.BIGINT, allowNull: true },
updatedBy: { type: DataTypes.BIGINT, allowNull: true },
deletedBy: { type: DataTypes.BIGINT, allowNull: true },
+30
View File
@@ -0,0 +1,30 @@
/***********************************************************************************************************************************************************************
* File Name: user_tier_grants.mdl.js
* Type of Program: Model
* Description: Purchase-time snapshot of the exact courses/units/lessons a
* Tier Plan purchase granted. Replaces live re-resolution off
* plan_courses/plan_units/plan_lessons at access-check time, so
* editing a plan's bundle later no longer retroactively changes
* what past purchasers can access. See hasItemGrant() in
* controllers/client/courses.controller.js.
* Author: Kenneth Obsequio (@lash0000)
* Date Created: Aug. 4, 2026
***********************************************************************************************************************************************************************/
const { DataTypes } = require('sequelize');
const sequelize = require('../../config/db.config');
const mdl_UserTierGrants = sequelize.define('UserTierGrant', {
id: { type: DataTypes.BIGINT, primaryKey: true, autoIncrement: true },
user_tier_id: { type: DataTypes.BIGINT, allowNull: false, label: 'User Tier ID' },
user_id: { type: DataTypes.BIGINT, allowNull: false, label: 'User ID' },
plan_id: { type: DataTypes.BIGINT, allowNull: true, label: 'Plan ID' },
item_type: { type: DataTypes.STRING(10), allowNull: false, label: 'Item Type' },
item_id: { type: DataTypes.BIGINT, allowNull: false, label: 'Item ID' },
granted_at: { type: DataTypes.DATE, allowNull: false, defaultValue: DataTypes.NOW, label: 'Granted At' },
}, {
tableName: 'user_tier_grants',
timestamps: true,
paranoid: false,
});
module.exports = mdl_UserTierGrants;