mirror of
https://github.com/rgrgogu/new_starr.git
synced 2026-09-27 00:12:54 +08:00
chore: relocate backend into apps/api ahead of monorepo merge
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,36 @@
|
||||
const { DataTypes } = require('sequelize');
|
||||
const sequelize = require('../../config/db.config');
|
||||
|
||||
const mdl_PaymentPolicies = sequelize.define('PaymentPolicy', {
|
||||
policy_id: {
|
||||
type: DataTypes.BIGINT,
|
||||
primaryKey: true,
|
||||
autoIncrement: true,
|
||||
},
|
||||
plan_id: {
|
||||
type: DataTypes.BIGINT,
|
||||
allowNull: true,
|
||||
unique: true,
|
||||
},
|
||||
promo_rules: {
|
||||
type: DataTypes.JSONB,
|
||||
allowNull: false,
|
||||
defaultValue: [],
|
||||
},
|
||||
refund_policy: {
|
||||
type: DataTypes.JSONB,
|
||||
allowNull: false,
|
||||
defaultValue: { allowed: true, window_value: 5, window_unit: 'minutes', reason_required: false },
|
||||
},
|
||||
allowed_providers: {
|
||||
type: DataTypes.JSONB,
|
||||
allowNull: false,
|
||||
defaultValue: ['paypal'],
|
||||
},
|
||||
}, {
|
||||
tableName: 'payment_policies',
|
||||
timestamps: true,
|
||||
paranoid: false,
|
||||
});
|
||||
|
||||
module.exports = mdl_PaymentPolicies;
|
||||
@@ -0,0 +1,16 @@
|
||||
/***********************************************************************************************************************************************************************
|
||||
* File Name: payments.attributes.js
|
||||
* Type of Program: Model Attributes Config
|
||||
* Description: DataTable column config for payments — used by paginate.util.js
|
||||
* Author: rgrgogu
|
||||
* Date Created: Jun. 9, 2026
|
||||
***********************************************************************************************************************************************************************/
|
||||
|
||||
const excludeAttributes = ['provider_payload'];
|
||||
const jsonbSchemas = {};
|
||||
const computedAttributes = [
|
||||
{ key: 'user_full_name', label: 'Full Name', type: 'text', order: 1, filterable: false, literal: `("user"."personal_info"->'name'->>'full_name')` },
|
||||
{ key: 'user.email', label: 'Email Address', type: 'text', order: 2, filterable: false },
|
||||
];
|
||||
|
||||
module.exports = { excludeAttributes, jsonbSchemas, computedAttributes };
|
||||
@@ -0,0 +1,44 @@
|
||||
/***********************************************************************************************************************************************************************
|
||||
* File Name: payments.mdl.js
|
||||
* Type of Program: Model
|
||||
* Description: Payment records for tier plan purchases.
|
||||
* provider_payload JSONB stores all provider-specific data:
|
||||
* {
|
||||
* order_id, ← PayPal order ID
|
||||
* capture_id, ← PayPal capture ID
|
||||
* payer_id, ← PayPal payer ID
|
||||
* approval_url, ← PayPal approval URL (stored at order creation)
|
||||
* checkout: { promo_code, subtotal, discount },
|
||||
* capture: { ...full PayPal capture response },
|
||||
* error: { ...PayPal error response if failed },
|
||||
* cancelled_at, cancelled_by
|
||||
* }
|
||||
* Author: Kenneth Obsequio (@lash0000)
|
||||
* Date Created: Jun. 9, 2026
|
||||
***********************************************************************************************************************************************************************/
|
||||
const { DataTypes } = require('sequelize');
|
||||
const sequelize = require('../../config/db.config');
|
||||
|
||||
const mdl_Payments = sequelize.define('Payment', {
|
||||
payment_id: { type: DataTypes.BIGINT, primaryKey: true, autoIncrement: true, label: 'Payment ID', hidden: true, order: 0, filterable: true },
|
||||
user_id: { type: DataTypes.BIGINT, allowNull: false, label: 'User ID', hidden: true, order: 1, filterable: true },
|
||||
plan_id: { type: DataTypes.BIGINT, allowNull: false, label: 'Plan ID', hidden: true, order: 2, filterable: true },
|
||||
tier_id: { type: DataTypes.BIGINT, allowNull: true, label: 'Tier ID', hidden: true, order: 3, filterable: true },
|
||||
status: { type: DataTypes.ENUM('pending', 'completed', 'failed', 'cancelled', 'expired', 'refunded'), allowNull: false, defaultValue: 'pending', label: 'Status', hidden: false, order: 4, filterable: true },
|
||||
amount: { type: DataTypes.DECIMAL(10, 2), allowNull: false, label: 'Amount', hidden: false, order: 3, filterable: false },
|
||||
currency: { type: DataTypes.STRING(10), allowNull: false, defaultValue: 'USD', label: 'Currency', hidden: false, order: 6, filterable: true },
|
||||
promo_code: { type: DataTypes.STRING(50), allowNull: true, label: 'Promo Code', hidden: false, order: 7, filterable: true },
|
||||
discount: { type: DataTypes.DECIMAL(10, 2), allowNull: false, defaultValue: 0.00, label: 'Discount', hidden: false, order: 8, filterable: false },
|
||||
provider: { type: DataTypes.STRING(50), allowNull: false, defaultValue: 'paypal', label: 'Provider', hidden: false, order: 9, filterable: true },
|
||||
provider_payload: { type: DataTypes.JSONB, allowNull: true, defaultValue: {}, label: 'Provider Payload', hidden: true, order: 10, filterable: false },
|
||||
paid_at: { type: DataTypes.DATE, allowNull: true, label: 'Paid At', hidden: false, order: 5, filterable: false },
|
||||
createdBy: { type: DataTypes.BIGINT, allowNull: true, label: 'Created By' },
|
||||
updatedBy: { type: DataTypes.BIGINT, allowNull: true, label: 'Updated By' },
|
||||
deletedBy: { type: DataTypes.BIGINT, allowNull: true, label: 'Deleted By' },
|
||||
}, {
|
||||
tableName: 'payments',
|
||||
timestamps: true,
|
||||
paranoid: true,
|
||||
});
|
||||
|
||||
module.exports = mdl_Payments;
|
||||
@@ -0,0 +1,28 @@
|
||||
/***********************************************************************************************************************************************************************
|
||||
* File Name: plan_courses.mdl.js
|
||||
* Type of Program: Model
|
||||
* Description: Junction table — links courses to a specific tier plan.
|
||||
* 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
|
||||
***********************************************************************************************************************************************************************/
|
||||
const { DataTypes } = require('sequelize');
|
||||
const sequelize = require('../../config/db.config');
|
||||
|
||||
const mdl_PlanCourses = sequelize.define('PlanCourse', {
|
||||
id: { type: DataTypes.BIGINT, primaryKey: true, autoIncrement: true },
|
||||
plan_id: { type: DataTypes.BIGINT, allowNull: false },
|
||||
course_id: { type: DataTypes.BIGINT, allowNull: false },
|
||||
}, {
|
||||
tableName: 'plan_courses',
|
||||
timestamps: true,
|
||||
paranoid: false,
|
||||
});
|
||||
|
||||
module.exports = mdl_PlanCourses;
|
||||
@@ -0,0 +1,27 @@
|
||||
/***********************************************************************************************************************************************************************
|
||||
* File Name: plan_lessons.mdl.js
|
||||
* Type of Program: Model
|
||||
* Description: Junction table — links standalone Lessons to a specific tier plan.
|
||||
* 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 / user_tier_grants).
|
||||
* Author: Kenneth Obsequio (@lash0000)
|
||||
* Date Created: Aug. 1, 2026
|
||||
***********************************************************************************************************************************************************************/
|
||||
const { DataTypes } = require('sequelize');
|
||||
const sequelize = require('../../config/db.config');
|
||||
|
||||
const mdl_PlanLessons = sequelize.define('PlanLesson', {
|
||||
id: { type: DataTypes.BIGINT, primaryKey: true, autoIncrement: true },
|
||||
plan_id: { type: DataTypes.BIGINT, allowNull: false },
|
||||
lesson_id: { type: DataTypes.BIGINT, allowNull: false },
|
||||
}, {
|
||||
tableName: 'plan_lessons',
|
||||
timestamps: true,
|
||||
paranoid: false,
|
||||
});
|
||||
|
||||
module.exports = mdl_PlanLessons;
|
||||
@@ -0,0 +1,27 @@
|
||||
/***********************************************************************************************************************************************************************
|
||||
* File Name: plan_units.mdl.js
|
||||
* Type of Program: Model
|
||||
* Description: Junction table — links standalone Units to a specific tier plan.
|
||||
* 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 / user_tier_grants).
|
||||
* Author: Kenneth Obsequio (@lash0000)
|
||||
* Date Created: Aug. 1, 2026
|
||||
***********************************************************************************************************************************************************************/
|
||||
const { DataTypes } = require('sequelize');
|
||||
const sequelize = require('../../config/db.config');
|
||||
|
||||
const mdl_PlanUnits = sequelize.define('PlanUnit', {
|
||||
id: { type: DataTypes.BIGINT, primaryKey: true, autoIncrement: true },
|
||||
plan_id: { type: DataTypes.BIGINT, allowNull: false },
|
||||
unit_id: { type: DataTypes.BIGINT, allowNull: false },
|
||||
}, {
|
||||
tableName: 'plan_units',
|
||||
timestamps: true,
|
||||
paranoid: false,
|
||||
});
|
||||
|
||||
module.exports = mdl_PlanUnits;
|
||||
@@ -0,0 +1,111 @@
|
||||
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_PlanUnits = require('./plan_units.mdl');
|
||||
const mdl_PlanLessons = require('./plan_lessons.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');
|
||||
const Unit = require('../courses/units.mdl');
|
||||
const Lesson = require('../courses/lessons.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' });
|
||||
|
||||
// ─── Payments ─────────────────────────────────────────────────────────────────
|
||||
mdl_Payments.belongsTo(mdl_Users, { foreignKey: 'user_id', as: 'user' });
|
||||
mdl_Payments.belongsTo(mdl_TierPlans, { foreignKey: 'plan_id', as: 'plan' });
|
||||
mdl_Payments.belongsTo(mdl_UserTiers, { foreignKey: 'tier_id', as: 'tier' });
|
||||
|
||||
// ─── Plan ↔ Courses ───────────────────────────────────────────────────────────
|
||||
mdl_TierPlans.belongsToMany(Course, {
|
||||
through: mdl_PlanCourses,
|
||||
foreignKey: 'plan_id',
|
||||
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.hasMany(mdl_PlanCourses, { as: 'planCourses', foreignKey: 'course_id' });
|
||||
mdl_TierPlans.hasMany(mdl_PlanCourses, { as: 'planCourses', foreignKey: 'plan_id' });
|
||||
|
||||
// ─── Plan ↔ Units ─────────────────────────────────────────────────────────────
|
||||
mdl_TierPlans.belongsToMany(Unit, {
|
||||
through: mdl_PlanUnits,
|
||||
foreignKey: 'plan_id',
|
||||
otherKey: 'unit_id',
|
||||
as: 'units',
|
||||
});
|
||||
Unit.belongsToMany(mdl_TierPlans, {
|
||||
through: mdl_PlanUnits,
|
||||
foreignKey: 'unit_id',
|
||||
otherKey: 'plan_id',
|
||||
as: 'plans',
|
||||
});
|
||||
mdl_PlanUnits.belongsTo(mdl_TierPlans, { foreignKey: 'plan_id', as: 'plan' });
|
||||
mdl_PlanUnits.belongsTo(Unit, { foreignKey: 'unit_id', as: 'unit' });
|
||||
Unit.hasMany(mdl_PlanUnits, { as: 'planUnits', foreignKey: 'unit_id' });
|
||||
mdl_TierPlans.hasMany(mdl_PlanUnits, { as: 'planUnits', foreignKey: 'plan_id' });
|
||||
|
||||
// ─── Plan ↔ Lessons ───────────────────────────────────────────────────────────
|
||||
mdl_TierPlans.belongsToMany(Lesson, {
|
||||
through: mdl_PlanLessons,
|
||||
foreignKey: 'plan_id',
|
||||
otherKey: 'lesson_id',
|
||||
as: 'lessons',
|
||||
});
|
||||
Lesson.belongsToMany(mdl_TierPlans, {
|
||||
through: mdl_PlanLessons,
|
||||
foreignKey: 'lesson_id',
|
||||
otherKey: 'plan_id',
|
||||
as: 'plans',
|
||||
});
|
||||
mdl_PlanLessons.belongsTo(mdl_TierPlans, { foreignKey: 'plan_id', as: 'plan' });
|
||||
mdl_PlanLessons.belongsTo(Lesson, { foreignKey: 'lesson_id', as: 'lesson' });
|
||||
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' });
|
||||
|
||||
// ─── 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' });
|
||||
|
||||
module.exports = {
|
||||
mdl_TierCategories,
|
||||
mdl_TierPlans,
|
||||
mdl_UserTiers,
|
||||
mdl_Payments,
|
||||
mdl_PlanCourses,
|
||||
mdl_PlanUnits,
|
||||
mdl_PlanLessons,
|
||||
mdl_SystemBadges,
|
||||
mdl_UserTierGrants,
|
||||
};
|
||||
@@ -0,0 +1,23 @@
|
||||
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' },
|
||||
is_special: { type: DataTypes.BOOLEAN, allowNull: false, defaultValue: false, label: 'Special' },
|
||||
}, {
|
||||
tableName: 'tier_categories',
|
||||
timestamps: true,
|
||||
paranoid: false,
|
||||
});
|
||||
|
||||
module.exports = mdl_TierCategories;
|
||||
@@ -0,0 +1,71 @@
|
||||
/***********************************************************************************************************************************************************************
|
||||
* File Name: tier_plans.attributes.js
|
||||
* Type of Program: Attributes
|
||||
* Description: Exclude list, display attributes, and computed fields for tier_plans.
|
||||
* Author: Kenneth Obsequio (@lash0000)
|
||||
* Date Created: Jun. 6, 2026
|
||||
***********************************************************************************************************************************************************************/
|
||||
|
||||
const excludeAttributes = [
|
||||
"tier_category_id",
|
||||
"description",
|
||||
];
|
||||
|
||||
const jsonbSchemas = {}; // no JSONB columns on this model
|
||||
|
||||
const computedAttributes = [
|
||||
{
|
||||
key: "courseCount", label: "Courses", type: "number", order: 100, filterable: false,
|
||||
literal: `(
|
||||
SELECT CAST(COUNT(*) AS INTEGER)
|
||||
FROM "plan_courses"
|
||||
INNER JOIN "courses" ON "courses"."course_id" = "plan_courses"."course_id"
|
||||
WHERE "plan_courses"."plan_id" = "TierPlan"."plan_id"
|
||||
AND "courses"."deletedAt" IS NULL
|
||||
)`,
|
||||
},
|
||||
{
|
||||
key: "unitCount", label: "Units", type: "number", order: 101, filterable: false,
|
||||
literal: `(
|
||||
SELECT CAST(COUNT(*) AS INTEGER)
|
||||
FROM "plan_units"
|
||||
INNER JOIN "units" ON "units"."unit_id" = "plan_units"."unit_id"
|
||||
WHERE "plan_units"."plan_id" = "TierPlan"."plan_id"
|
||||
AND "units"."deletedAt" IS NULL
|
||||
)`,
|
||||
},
|
||||
{
|
||||
key: "lessonCount", label: "Lessons", type: "number", order: 102, filterable: false,
|
||||
literal: `(
|
||||
SELECT CAST(COUNT(*) AS INTEGER)
|
||||
FROM "plan_lessons"
|
||||
INNER JOIN "lessons" ON "lessons"."lesson_id" = "plan_lessons"."lesson_id"
|
||||
WHERE "plan_lessons"."plan_id" = "TierPlan"."plan_id"
|
||||
AND "lessons"."deletedAt" IS NULL
|
||||
)`,
|
||||
},
|
||||
{
|
||||
key: "bundleCount", label: "Bundles", type: "number", order: 103, filterable: false,
|
||||
literal: `(
|
||||
(SELECT CAST(COUNT(*) AS INTEGER)
|
||||
FROM "plan_courses"
|
||||
INNER JOIN "courses" ON "courses"."course_id" = "plan_courses"."course_id"
|
||||
WHERE "plan_courses"."plan_id" = "TierPlan"."plan_id"
|
||||
AND "courses"."deletedAt" IS NULL)
|
||||
+
|
||||
(SELECT CAST(COUNT(*) AS INTEGER)
|
||||
FROM "plan_units"
|
||||
INNER JOIN "units" ON "units"."unit_id" = "plan_units"."unit_id"
|
||||
WHERE "plan_units"."plan_id" = "TierPlan"."plan_id"
|
||||
AND "units"."deletedAt" IS NULL)
|
||||
+
|
||||
(SELECT CAST(COUNT(*) AS INTEGER)
|
||||
FROM "plan_lessons"
|
||||
INNER JOIN "lessons" ON "lessons"."lesson_id" = "plan_lessons"."lesson_id"
|
||||
WHERE "plan_lessons"."plan_id" = "TierPlan"."plan_id"
|
||||
AND "lessons"."deletedAt" IS NULL)
|
||||
)`,
|
||||
},
|
||||
];
|
||||
|
||||
module.exports = { excludeAttributes, jsonbSchemas, computedAttributes };
|
||||
@@ -0,0 +1,35 @@
|
||||
/***********************************************************************************************************************************************************************
|
||||
* File Name: tier_plans.mdl.js
|
||||
* Type of Program: Model
|
||||
* Description: Sequelize model for the `tier_plans` table.
|
||||
* Catalog of fixed plans (premium/exclusive) with duration and price.
|
||||
* Author: Kenneth Obsequio (@lash0000)
|
||||
* Date Created: Jun. 6, 2026
|
||||
***********************************************************************************************************************************************************************/
|
||||
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_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' },
|
||||
description: { type: DataTypes.TEXT, allowNull: true, label: 'Description' },
|
||||
features: { type: DataTypes.JSONB, allowNull: true, label: 'Features', comment: 'Array of {text} — admin-authored "what\'s included" bullets shown on the client Plans page.' },
|
||||
duration_days: { type: DataTypes.FLOAT, allowNull: false, label: 'Duration (Days)' },
|
||||
duration_unit: { type: DataTypes.STRING(10), allowNull: false, defaultValue: 'day', label: 'Duration Unit' },
|
||||
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' },
|
||||
is_recommended: { type: DataTypes.BOOLEAN, allowNull: false, defaultValue: false, label: 'Recommended', comment: 'Highlights this plan with the "Recommended for you" banner on the client Plans page.' },
|
||||
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 },
|
||||
}, {
|
||||
tableName: 'tier_plans',
|
||||
timestamps: true,
|
||||
paranoid: true,
|
||||
});
|
||||
|
||||
module.exports = mdl_TierPlans;
|
||||
@@ -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;
|
||||
@@ -0,0 +1,31 @@
|
||||
/***********************************************************************************************************************************************************************
|
||||
* File Name: user_tiers.mdl.js
|
||||
* Type of Program: Model
|
||||
* Description: Sequelize model for the `user_tiers` table.
|
||||
* Full history of tier grants per user.
|
||||
* Author: Kenneth Obsequio (@lash0000)
|
||||
* Date Created: Jun. 6, 2026
|
||||
***********************************************************************************************************************************************************************/
|
||||
const { DataTypes } = require('sequelize');
|
||||
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.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' },
|
||||
notes: { type: DataTypes.TEXT, allowNull: true, label: 'Notes' },
|
||||
}, {
|
||||
tableName: 'user_tiers',
|
||||
timestamps: true,
|
||||
paranoid: false,
|
||||
});
|
||||
|
||||
module.exports = mdl_UserTiers;
|
||||
Reference in New Issue
Block a user