mirror of
https://github.com/rgrgogu/new_starr.git
synced 2026-09-27 00:12:54 +08:00
ready to test
Testing Signed-off-by: Kenneth Obsequio <k80308392@gmail.com>
This commit is contained in:
@@ -0,0 +1,13 @@
|
||||
/***********************************************************************************************************************************************************************
|
||||
* 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 = [];
|
||||
|
||||
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: 5, 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: 11, 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,22 @@
|
||||
/***********************************************************************************************************************************************************************
|
||||
* 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.
|
||||
* 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,39 @@
|
||||
const mdl_Users = require('../users/users.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 { Course } = require('../courses/courses.mdl'); // ← named export
|
||||
|
||||
// ─── 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.hasOne(mdl_PlanCourses, { as: 'planCourse', foreignKey: 'course_id' });
|
||||
mdl_TierPlans.hasMany(mdl_PlanCourses, { as: 'planCourses', foreignKey: 'plan_id' });
|
||||
|
||||
module.exports = { mdl_TierPlans, mdl_UserTiers, mdl_Payments, mdl_PlanCourses };
|
||||
@@ -0,0 +1,17 @@
|
||||
/***********************************************************************************************************************************************************************
|
||||
* 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 = [
|
||||
// nothing hidden by default — all columns are safe to expose to admin
|
||||
];
|
||||
|
||||
const jsonbSchemas = {}; // no JSONB columns on this model
|
||||
|
||||
const computedAttributes = []; // no computed fields needed
|
||||
|
||||
module.exports = { excludeAttributes, jsonbSchemas, computedAttributes };
|
||||
@@ -0,0 +1,26 @@
|
||||
/***********************************************************************************************************************************************************************
|
||||
* 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: { type: DataTypes.ENUM('premium', 'exclusive'), allowNull: false, label: 'Tier' },
|
||||
label: { type: DataTypes.STRING(100), allowNull: false, label: 'Plan Label' },
|
||||
duration_days: { type: DataTypes.INTEGER, allowNull: false, label: 'Duration (Days)' },
|
||||
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' },
|
||||
}, {
|
||||
tableName: 'tier_plans',
|
||||
timestamps: true,
|
||||
paranoid: true,
|
||||
});
|
||||
|
||||
module.exports = mdl_TierPlans;
|
||||
@@ -0,0 +1,30 @@
|
||||
/***********************************************************************************************************************************************************************
|
||||
* 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.ENUM('free', 'premium', 'exclusive'), 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' },
|
||||
|
||||
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