114 lines
3.3 KiB
JavaScript
114 lines
3.3 KiB
JavaScript
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
|
|
// Cấu trúc content_json phụ thuộc vào lesson_content_type:
|
|
// - vocabulary: { type: "vocabulary", vocabulary_ids: [uuid1, uuid2, ...], exercises: [...] }
|
|
// - grammar: { type: "grammar", grammar_ids: [uuid1, uuid2, ...], examples: [...], exercises: [...] }
|
|
// - phonics: { type: "phonics", phonics_rules: [{ipa: "/æ/", words: [...]}], exercises: [...] }
|
|
// - review: { type: "review", sections: [{type: "vocabulary", ...}, {type: "grammar", ...}, {type: "phonics", ...}] }
|
|
content_json: {
|
|
type: DataTypes.JSON,
|
|
comment: 'Nội dung học tập dạng JSON: vocabulary, grammar, phonics, review'
|
|
},
|
|
|
|
// Loại nội dung của bài học (để query dễ dàng)
|
|
lesson_content_type: {
|
|
type: DataTypes.ENUM('vocabulary', 'grammar', 'phonics', 'review', 'mixed'),
|
|
allowNull: true,
|
|
comment: 'Loại nội dung: vocabulary, grammar, phonics, review, mixed'
|
|
},
|
|
|
|
// 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;
|