const { DataTypes } = require('sequelize'); const { sequelize } = require('../config/database'); /** * LessonStory Model - Pivot table for N-N relationship * Many-to-Many: Lessons <-> Stories */ const LessonStory = sequelize.define('lesson_stories', { id: { type: DataTypes.UUID, defaultValue: DataTypes.UUIDV4, primaryKey: true, }, lesson_id: { type: DataTypes.UUID, allowNull: false, comment: 'ID của bài học', }, story_id: { type: DataTypes.UUID, allowNull: false, comment: 'ID của story', }, display_order: { type: DataTypes.INTEGER, defaultValue: 0, comment: 'Thứ tự hiển thị story trong lesson', }, is_required: { type: DataTypes.BOOLEAN, defaultValue: true, comment: 'Story này có bắt buộc hoàn thành không', }, created_at: { type: DataTypes.DATE, allowNull: false, defaultValue: DataTypes.NOW, }, updated_at: { type: DataTypes.DATE, allowNull: false, defaultValue: DataTypes.NOW, }, }, { tableName: 'lesson_stories', timestamps: true, underscored: true, indexes: [ { fields: ['lesson_id'] }, { fields: ['story_id'] }, { fields: ['lesson_id', 'story_id'], unique: true }, { fields: ['display_order'] }, ], }); module.exports = LessonStory;