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;