mirror of
https://github.com/rgrgogu/new_starr.git
synced 2026-09-27 00:12:54 +08:00
client and some admin new
Signed-off-by: Kenneth Obsequio <k80308392@gmail.com>
This commit is contained in:
@@ -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
|
||||
***********************************************************************************************************************************************************************/
|
||||
|
||||
@@ -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
|
||||
***********************************************************************************************************************************************************************/
|
||||
|
||||
@@ -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;
|
||||
@@ -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
|
||||
***********************************************************************************************************************************************************************/
|
||||
|
||||
@@ -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,
|
||||
};
|
||||
|
||||
@@ -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 },
|
||||
|
||||
@@ -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;
|
||||
Reference in New Issue
Block a user