update
This commit is contained in:
69
models/Chapter.js
Normal file
69
models/Chapter.js
Normal file
@@ -0,0 +1,69 @@
|
||||
const { DataTypes } = require('sequelize');
|
||||
const { sequelize } = require('../config/database');
|
||||
|
||||
/**
|
||||
* Chapter Model - Chương trong giáo trình
|
||||
* Một Subject có nhiều Chapter
|
||||
*/
|
||||
const Chapter = sequelize.define('chapters', {
|
||||
id: {
|
||||
type: DataTypes.UUID,
|
||||
defaultValue: DataTypes.UUIDV4,
|
||||
primaryKey: true
|
||||
},
|
||||
subject_id: {
|
||||
type: DataTypes.UUID,
|
||||
allowNull: false,
|
||||
comment: 'ID của giáo trình'
|
||||
},
|
||||
chapter_number: {
|
||||
type: DataTypes.INTEGER,
|
||||
allowNull: false,
|
||||
comment: 'Số thứ tự chương (1, 2, 3...)'
|
||||
},
|
||||
chapter_title: {
|
||||
type: DataTypes.STRING(200),
|
||||
allowNull: false,
|
||||
comment: 'Tiêu đề chương'
|
||||
},
|
||||
chapter_description: {
|
||||
type: DataTypes.TEXT,
|
||||
comment: 'Mô tả về chương học'
|
||||
},
|
||||
duration_minutes: {
|
||||
type: DataTypes.INTEGER,
|
||||
comment: 'Thời lượng học (phút)'
|
||||
},
|
||||
is_published: {
|
||||
type: DataTypes.BOOLEAN,
|
||||
defaultValue: false,
|
||||
comment: 'Đã xuất bản chưa'
|
||||
},
|
||||
display_order: {
|
||||
type: DataTypes.INTEGER,
|
||||
defaultValue: 0,
|
||||
comment: 'Thứ tự hiển thị'
|
||||
},
|
||||
created_at: {
|
||||
type: DataTypes.DATE,
|
||||
allowNull: false,
|
||||
defaultValue: DataTypes.NOW
|
||||
},
|
||||
updated_at: {
|
||||
type: DataTypes.DATE,
|
||||
allowNull: false,
|
||||
defaultValue: DataTypes.NOW
|
||||
},
|
||||
}, {
|
||||
tableName: 'chapters',
|
||||
timestamps: true,
|
||||
underscored: true,
|
||||
indexes: [
|
||||
{ fields: ['subject_id'] },
|
||||
{ fields: ['subject_id', 'chapter_number'], unique: true },
|
||||
{ fields: ['display_order'] },
|
||||
{ fields: ['is_published'] },
|
||||
],
|
||||
});
|
||||
|
||||
module.exports = Chapter;
|
||||
Reference in New Issue
Block a user