mirror of
https://github.com/rgrgogu/new_starr.git
synced 2026-09-27 00:12:54 +08:00
@@ -0,0 +1,16 @@
|
||||
'use strict';
|
||||
|
||||
const { DataTypes } = require('sequelize');
|
||||
const sequelize = require('../../config/db.config');
|
||||
|
||||
const CourseAchievement = sequelize.define('CourseAchievement', {
|
||||
id: { type: DataTypes.BIGINT, primaryKey: true, autoIncrement: true },
|
||||
course_id: { type: DataTypes.BIGINT, allowNull: false },
|
||||
achievement_key: { type: DataTypes.STRING(100), allowNull: false },
|
||||
order_index: { type: DataTypes.INTEGER, defaultValue: 0 },
|
||||
}, {
|
||||
tableName: 'course_achievements',
|
||||
timestamps: true,
|
||||
});
|
||||
|
||||
module.exports = CourseAchievement;
|
||||
@@ -21,6 +21,7 @@ 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");
|
||||
const CourseAchievement = require("./course_achievement.mdl");
|
||||
|
||||
// ── CourseReadingProgress ─────────────────────────────────────────────────────
|
||||
CourseReadingProgress.belongsTo(mdl_Users, { foreignKey: 'user_id', as: 'user' });
|
||||
@@ -51,9 +52,11 @@ Course.hasMany(CourseObjective, { as: "objectives", foreignKey: "course_id" });
|
||||
Course.hasMany(CoursePrerequisite, { as: "prerequisites", foreignKey: "course_id" });
|
||||
Course.hasOne(CourseAssessment, { as: "assessment", foreignKey: "course_id" });
|
||||
Course.hasMany(Certificate, { as: "certificates", foreignKey: "course_id" });
|
||||
Course.hasMany(CourseInstructor, { as: "instructors", foreignKey: "course_id" });
|
||||
Course.hasMany(CourseInstructor, { as: "instructors", foreignKey: "course_id" });
|
||||
CourseInstructor.belongsTo(Course, { as: "course", foreignKey: "course_id" });
|
||||
CourseInstructor.belongsTo(mdl_Users, { as: "user", foreignKey: "user_id" });
|
||||
Course.hasMany(CourseAchievement, { as: "courseAchievements", foreignKey: "course_id" });
|
||||
CourseAchievement.belongsTo(Course, { as: "course", foreignKey: "course_id" });
|
||||
Course.belongsToMany(mdl_Category, { through: CourseProductCategory, foreignKey: 'course_id', otherKey: 'category_id', as: 'categories' });
|
||||
mdl_Category.belongsToMany(Course, { through: CourseProductCategory, foreignKey: 'category_id', otherKey: 'course_id', as: 'courses' });
|
||||
|
||||
@@ -117,4 +120,5 @@ module.exports = {
|
||||
AssessmentSession, QuizSession,
|
||||
mdl_Category, Certificate, CourseInstructor,
|
||||
CourseReadingProgress, UnitReadingProgress, LessonReadingProgress,
|
||||
CourseAchievement,
|
||||
};
|
||||
@@ -10,7 +10,10 @@ const Course = sequelize.define("Course", {
|
||||
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.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 },
|
||||
duration_seconds: { type: DataTypes.INTEGER, allowNull: true, defaultValue: 0, hidden: false, order: 8, filterable: false },
|
||||
badge_color: { type: DataTypes.STRING(50), allowNull: true, defaultValue: "purple" },
|
||||
badge_asset_id: { type: DataTypes.BIGINT, allowNull: true },
|
||||
badge_image_url: { type: DataTypes.TEXT, allowNull: true },
|
||||
createdBy: { type: DataTypes.BIGINT, allowNull: true },
|
||||
updatedBy: { type: DataTypes.BIGINT, allowNull: true },
|
||||
deletedBy: { type: DataTypes.BIGINT, allowNull: true },
|
||||
|
||||
@@ -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,26 @@
|
||||
/***********************************************************************************************************************************************************************
|
||||
* File Name: plan_prices.mdl.js
|
||||
* Type of Program: Model
|
||||
* Description: Admin-managed localized price overrides for tier plans.
|
||||
* One row per (plan_id, currency) pair. When a user's preferred_currency
|
||||
* matches a row here, the override price is shown instead of the base price.
|
||||
* Author: Kenneth Obsequio (@lash0000)
|
||||
* Date Created: Jun. 29, 2026
|
||||
***********************************************************************************************************************************************************************/
|
||||
'use strict';
|
||||
|
||||
const { DataTypes } = require('sequelize');
|
||||
const sequelize = require('../../config/db.config');
|
||||
|
||||
const mdl_PlanPrices = sequelize.define('PlanPrice', {
|
||||
price_id: { type: DataTypes.BIGINT, primaryKey: true, autoIncrement: true },
|
||||
plan_id: { type: DataTypes.BIGINT, allowNull: false },
|
||||
currency: { type: DataTypes.CHAR(3), allowNull: false, label: 'Currency' },
|
||||
price: { type: DataTypes.DECIMAL(10, 2), allowNull: false, label: 'Price' },
|
||||
}, {
|
||||
tableName: 'plan_prices',
|
||||
timestamps: true,
|
||||
paranoid: false,
|
||||
});
|
||||
|
||||
module.exports = mdl_PlanPrices;
|
||||
@@ -5,6 +5,7 @@ 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_PlanPrices = require('./plan_prices.mdl');
|
||||
const mdl_SystemBadges = require('../system_badges/system_badges.mdl');
|
||||
const Asset = require('../assets/assets.mdl');
|
||||
const { Course } = require('../courses/courses.mdl');
|
||||
@@ -53,6 +54,10 @@ mdl_TierPlans.hasMany(mdl_UserTiers, { foreignKey: 'plan_id', as: 'userTiers'
|
||||
mdl_TierPlans.hasOne(mdl_PlanPolicies, { foreignKey: 'plan_id', as: 'policy' });
|
||||
mdl_PlanPolicies.belongsTo(mdl_TierPlans, { foreignKey: 'plan_id', as: 'plan' });
|
||||
|
||||
// ─── Plan ↔ Localized Prices ──────────────────────────────────────────────────
|
||||
mdl_TierPlans.hasMany(mdl_PlanPrices, { foreignKey: 'plan_id', as: 'prices' });
|
||||
mdl_PlanPrices.belongsTo(mdl_TierPlans, { foreignKey: 'plan_id', as: 'plan' });
|
||||
|
||||
// ─── SystemBadge → Asset ─────────────────────────────────────────────────────
|
||||
mdl_SystemBadges.belongsTo(Asset, { foreignKey: 'asset_id', as: 'asset' });
|
||||
|
||||
@@ -63,5 +68,6 @@ module.exports = {
|
||||
mdl_Payments,
|
||||
mdl_PlanCourses,
|
||||
mdl_PlanPolicies,
|
||||
mdl_PlanPrices,
|
||||
mdl_SystemBadges,
|
||||
};
|
||||
|
||||
@@ -7,7 +7,8 @@
|
||||
***********************************************************************************************************************************************************************/
|
||||
|
||||
const excludeAttributes = [
|
||||
// nothing hidden by default — all columns are safe to expose to admin
|
||||
"tier_category_id",
|
||||
"description",
|
||||
];
|
||||
|
||||
const jsonbSchemas = {}; // no JSONB columns on this model
|
||||
|
||||
@@ -13,8 +13,10 @@ 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' },
|
||||
duration_days: { type: DataTypes.INTEGER, allowNull: false, label: 'Duration (Days)' },
|
||||
label: { type: DataTypes.STRING(100), allowNull: false, label: 'Plan Label' },
|
||||
description: { type: DataTypes.TEXT, allowNull: true, label: 'Description' },
|
||||
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' },
|
||||
|
||||
@@ -43,6 +43,9 @@ const mdl_Users = sequelize.define('User', {
|
||||
*/
|
||||
personal_info: { type: DataTypes.JSONB, defaultValue: null, label: "Personal Info", order: 2 },
|
||||
|
||||
// ── Currency preference ──────────────────────────────────────────────────────
|
||||
preferred_currency: { type: DataTypes.CHAR(3), allowNull: false, defaultValue: 'USD', label: 'Preferred Currency' },
|
||||
|
||||
// ── 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" },
|
||||
|
||||
Reference in New Issue
Block a user