tier plans improving

Signed-off-by: Kenneth Obsequio <k80308392@gmail.com>
This commit is contained in:
2026-08-01 23:02:31 +08:00
parent cae958b5d5
commit c5052fda4c
15 changed files with 371 additions and 41 deletions
+1 -1
View File
@@ -13,7 +13,7 @@ const Asset = sequelize.define("Asset", {
original_name: { type: DataTypes.STRING(255), allowNull: false, label: "Original Name", order: 0, hidden: true },
display_name: { type: DataTypes.STRING(255), allowNull: false, label: "Name", order: 0, filterable: true },
file_url: { type: DataTypes.STRING(512), allowNull: false, label: "File URL", order: 0, hidden: true },
file_size: { type: DataTypes.BIGINT, allowNull: false, label: "File Size", order: 0, hidden: true },
file_size: { type: DataTypes.BIGINT, allowNull: false, label: "File Size", order: 0 },
mime_type: { type: DataTypes.STRING(100), allowNull: false, label: "MIME Type", order: 0, hidden: true },
extension: { type: DataTypes.STRING(20), label: "File Type", order: 0, filterable: true },
checksum: { type: DataTypes.STRING(64), label: "Checksum", order: 0, hidden: true },
+1
View File
@@ -13,6 +13,7 @@ const mdl_TierCategories = sequelize.define('TierCategory', {
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,
+54 -1
View File
@@ -13,6 +13,59 @@ const excludeAttributes = [
const jsonbSchemas = {}; // no JSONB columns on this model
const computedAttributes = []; // no computed fields needed
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 };
+3
View File
@@ -21,6 +21,9 @@ 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' },
createdBy: { type: DataTypes.BIGINT, allowNull: true },
updatedBy: { type: DataTypes.BIGINT, allowNull: true },
deletedBy: { type: DataTypes.BIGINT, allowNull: true },
}, {
tableName: 'tier_plans',
timestamps: true,