Files
sena_db_api_layer/models/Lesson.js
silverpro89 d3da098f6f
All checks were successful
Deploy to Production / deploy (push) Successful in 22s
update sentences API
2026-02-24 14:29:23 +07:00

95 lines
2.4 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'
},
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'
},
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.TEXT,
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;