added: course func()

Signed-off-by: Kenneth Obsequio <k80308392@gmail.com>
This commit is contained in:
2026-05-16 11:04:36 +08:00
parent c3663572ae
commit 6907e9bb2d
8 changed files with 596 additions and 6 deletions
+32
View File
@@ -0,0 +1,32 @@
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" },
}, {
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" });
module.exports = Course;
+23
View File
@@ -0,0 +1,23 @@
const { DataTypes } = require("sequelize");
const sequelize = require("../../config/db.config");
const mdl_Users = require("../users/users.mdl");
const Lesson = require("./lessons.mdl");
const LessonPage = sequelize.define("LessonPage", {
page_id: { type: DataTypes.BIGINT, primaryKey: true, autoIncrement: true },
lesson_id: { type: DataTypes.BIGINT, allowNull: false, unique: true },
blocks: { type: DataTypes.JSONB, allowNull: false, defaultValue: [] },
createdBy: { type: DataTypes.BIGINT, allowNull: true, label: "Created By" },
updatedBy: { type: DataTypes.BIGINT, allowNull: true, label: "Updated By" },
}, {
tableName: "lesson_pages",
timestamps: true,
paranoid: false,
});
LessonPage.belongsTo(Lesson, { as: "lesson", foreignKey: "lesson_id" });
LessonPage.belongsTo(mdl_Users, { as: "creator", foreignKey: "createdBy" });
LessonPage.belongsTo(mdl_Users, { as: "updater", foreignKey: "updatedBy" });
Lesson.hasOne(LessonPage, { as: "page", foreignKey: "lesson_id" });
module.exports = LessonPage;
+33
View File
@@ -0,0 +1,33 @@
const { DataTypes } = require("sequelize");
const sequelize = require("../../config/db.config");
const mdl_Users = require("../users/users.mdl");
const Unit = require("./units.mdl");
const Lesson = sequelize.define("Lesson", {
lesson_id: { type: DataTypes.BIGINT, primaryKey: true, autoIncrement: true },
uuid: { type: DataTypes.UUID, defaultValue: DataTypes.UUIDV4, allowNull: false, unique: true },
unit_id: { type: DataTypes.BIGINT, allowNull: false },
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" },
}, {
tableName: "lessons",
timestamps: true,
paranoid: true,
indexes: [
{ fields: ["uuid"] },
{ fields: ["unit_id"] },
{ fields: ["order_index"] },
{ fields: ["deletedAt"] },
],
});
Lesson.belongsTo(Unit, { as: "unit", foreignKey: "unit_id" });
Lesson.belongsTo(mdl_Users, { as: "creator", foreignKey: "createdBy" });
Lesson.belongsTo(mdl_Users, { as: "updater", foreignKey: "updatedBy" });
Unit.hasMany(Lesson, { as: "lessons", foreignKey: "unit_id" });
module.exports = Lesson;
+33
View File
@@ -0,0 +1,33 @@
const { DataTypes } = require("sequelize");
const sequelize = require("../../config/db.config");
const mdl_Users = require("../users/users.mdl");
const Course = require("./courses.mdl");
const Unit = sequelize.define("Unit", {
unit_id: { type: DataTypes.BIGINT, primaryKey: true, autoIncrement: true },
uuid: { type: DataTypes.UUID, defaultValue: DataTypes.UUIDV4, allowNull: false, unique: true },
course_id: { type: DataTypes.BIGINT, allowNull: false },
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" },
}, {
tableName: "units",
timestamps: true,
paranoid: true,
indexes: [
{ fields: ["uuid"] },
{ fields: ["course_id"] },
{ fields: ["order_index"] },
{ fields: ["deletedAt"] },
],
});
Unit.belongsTo(Course, { as: "course", foreignKey: "course_id" });
Unit.belongsTo(mdl_Users, { as: "creator", foreignKey: "createdBy" });
Unit.belongsTo(mdl_Users, { as: "updater", foreignKey: "updatedBy" });
Course.hasMany(Unit, { as: "units", foreignKey: "course_id" });
module.exports = Unit;