This commit is contained in:
rgrgogu
2026-05-20 13:22:29 +08:00
parent 6907e9bb2d
commit 6a5145f553
26 changed files with 2615 additions and 221 deletions
+37 -21
View File
@@ -1,32 +1,48 @@
const { DataTypes } = require("sequelize");
const sequelize = require("../../config/db.config");
const mdl_Users = require("../users/users.mdl");
const Course = sequelize.define("Course", {
course_id: { type: DataTypes.BIGINT, primaryKey: true, autoIncrement: true },
uuid: { type: DataTypes.UUID, defaultValue: DataTypes.UUIDV4, allowNull: false, unique: true },
title: { type: DataTypes.STRING(255), allowNull: false, label: "Title" },
description: { type: DataTypes.TEXT, allowNull: true, label: "Description" },
order_index: { type: DataTypes.INTEGER, allowNull: false, defaultValue: 0, label: "Order" },
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" },
course_id: { type: DataTypes.BIGINT, primaryKey: true, autoIncrement: true, hidden: true, order: 0, filterable: true },
uuid: { type: DataTypes.UUID, defaultValue: DataTypes.UUIDV4, allowNull: false, unique: true, hidden: true, order: 0, filterable: true },
title: { type: DataTypes.STRING(255), allowNull: false, hidden: false, order: 2, filterable: true },
description: { type: DataTypes.TEXT, allowNull: true, hidden: true, order: 0, filterable: true },
course_code: { type: DataTypes.STRING(50), allowNull: true, unique: true, hidden: false, order: 1, filterable: true },
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.ENUM("free", "premium"), 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 },
createdBy: { type: DataTypes.BIGINT, allowNull: true },
updatedBy: { type: DataTypes.BIGINT, allowNull: true },
deletedBy: { type: DataTypes.BIGINT, allowNull: true },
}, {
tableName: "courses",
timestamps: true,
paranoid: true,
indexes: [
{ fields: ["uuid"] },
{ fields: ["order_index"] },
{ fields: ["deletedAt"] },
],
});
Course.belongsTo(mdl_Users, { as: "creator", foreignKey: "createdBy" });
Course.belongsTo(mdl_Users, { as: "updater", foreignKey: "updatedBy" });
// ── Junction Tables ───────────────────────────────────────────────────────────
module.exports = Course;
const CourseProduct = sequelize.define("CourseProduct", {
id: { type: DataTypes.BIGINT, primaryKey: true, autoIncrement: true },
course_id: { type: DataTypes.BIGINT, allowNull: false },
product_id: { type: DataTypes.BIGINT, allowNull: false },
}, { tableName: "course_products", timestamps: true });
const CourseRole = sequelize.define("CourseRole", {
id: { type: DataTypes.BIGINT, primaryKey: true, autoIncrement: true },
course_id: { type: DataTypes.BIGINT, allowNull: false },
role_id: { type: DataTypes.BIGINT, allowNull: false },
}, { tableName: "course_roles", timestamps: true });
const CourseProductCategory = sequelize.define("CourseProductCategory", {
id: { type: DataTypes.BIGINT, primaryKey: true, autoIncrement: true },
course_id: { type: DataTypes.BIGINT, allowNull: false },
category_id: { type: DataTypes.BIGINT, allowNull: false },
}, { tableName: "course_product_categories", timestamps: true });
module.exports = {
Course,
CourseProduct,
CourseRole,
CourseProductCategory,
};