Files
sena_db_api_layer/models/LessonStory.js
Ken 6287a019e3
All checks were successful
Deploy to Production / deploy (push) Successful in 20s
update
2026-02-27 09:38:39 +07:00

57 lines
1.3 KiB
JavaScript

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;