update
This commit is contained in:
101
models/Lesson.js
Normal file
101
models/Lesson.js
Normal file
@@ -0,0 +1,101 @@
|
||||
const { DataTypes } = require('sequelize');
|
||||
const { sequelize } = require('../config/database');
|
||||
|
||||
/**
|
||||
* Lesson Model - Bài học trong chương
|
||||
* Một Chapter có nhiều Lesson
|
||||
*/
|
||||
const Lesson = sequelize.define('lessons', {
|
||||
id: {
|
||||
type: DataTypes.UUID,
|
||||
defaultValue: DataTypes.UUIDV4,
|
||||
primaryKey: true
|
||||
},
|
||||
chapter_id: {
|
||||
type: DataTypes.UUID,
|
||||
allowNull: false,
|
||||
comment: 'ID của chương'
|
||||
},
|
||||
lesson_number: {
|
||||
type: DataTypes.INTEGER,
|
||||
allowNull: false,
|
||||
comment: 'Số thứ tự bài học (1, 2, 3...)'
|
||||
},
|
||||
lesson_title: {
|
||||
type: DataTypes.STRING(200),
|
||||
allowNull: false,
|
||||
comment: 'Tiêu đề bài học'
|
||||
},
|
||||
lesson_type: {
|
||||
type: DataTypes.ENUM('json_content', 'url_content'),
|
||||
defaultValue: 'json_content',
|
||||
comment: 'Loại bài học: json_content (nội dung JSON) hoặc url_content (URL)'
|
||||
},
|
||||
lesson_description: {
|
||||
type: DataTypes.TEXT,
|
||||
comment: 'Mô tả bài học'
|
||||
},
|
||||
|
||||
// Dạng 1: JSON Content - Nội dung học tập dạng JSON
|
||||
content_json: {
|
||||
type: DataTypes.JSON,
|
||||
comment: 'Nội dung học tập dạng JSON: text, quiz, interactive, assignment, etc.'
|
||||
},
|
||||
|
||||
// Dạng 2: URL Content - Chứa link external
|
||||
content_url: {
|
||||
type: DataTypes.STRING(500),
|
||||
comment: 'URL nội dung: video, audio, document, external link'
|
||||
},
|
||||
content_type: {
|
||||
type: DataTypes.STRING(50),
|
||||
comment: 'Loại content cho URL: video, audio, pdf, external_link, youtube, etc.'
|
||||
},
|
||||
|
||||
duration_minutes: {
|
||||
type: DataTypes.INTEGER,
|
||||
comment: 'Thời lượng (phút)'
|
||||
},
|
||||
is_published: {
|
||||
type: DataTypes.BOOLEAN,
|
||||
defaultValue: false,
|
||||
comment: 'Đã xuất bản'
|
||||
},
|
||||
is_free: {
|
||||
type: DataTypes.BOOLEAN,
|
||||
defaultValue: false,
|
||||
comment: 'Cho phép học thử miễn phí'
|
||||
},
|
||||
display_order: {
|
||||
type: DataTypes.INTEGER,
|
||||
defaultValue: 0,
|
||||
comment: 'Thứ tự hiển thị'
|
||||
},
|
||||
thumbnail_url: {
|
||||
type: DataTypes.STRING(500),
|
||||
comment: 'URL ảnh thumbnail'
|
||||
},
|
||||
created_at: {
|
||||
type: DataTypes.DATE,
|
||||
allowNull: false,
|
||||
defaultValue: DataTypes.NOW
|
||||
},
|
||||
updated_at: {
|
||||
type: DataTypes.DATE,
|
||||
allowNull: false,
|
||||
defaultValue: DataTypes.NOW
|
||||
},
|
||||
}, {
|
||||
tableName: 'lessons',
|
||||
timestamps: true,
|
||||
underscored: true,
|
||||
indexes: [
|
||||
{ fields: ['chapter_id'] },
|
||||
{ fields: ['chapter_id', 'lesson_number'], unique: true },
|
||||
{ fields: ['display_order'] },
|
||||
{ fields: ['is_published'] },
|
||||
{ fields: ['lesson_type'] },
|
||||
],
|
||||
});
|
||||
|
||||
module.exports = Lesson;
|
||||
Reference in New Issue
Block a user