101 lines
2.3 KiB
JavaScript
101 lines
2.3 KiB
JavaScript
const { DataTypes } = require('sequelize');
|
|
const { sequelize } = require('../config/database');
|
|
|
|
/**
|
|
* LessonComponentProgress Model
|
|
* Theo dõi tiến độ học viên cho từng component trong composite lesson
|
|
*/
|
|
const LessonComponentProgress = sequelize.define('lesson_component_progress', {
|
|
id: {
|
|
type: DataTypes.UUID,
|
|
defaultValue: DataTypes.UUIDV4,
|
|
primaryKey: true
|
|
},
|
|
user_id: {
|
|
type: DataTypes.UUID,
|
|
allowNull: false,
|
|
comment: 'ID học viên'
|
|
},
|
|
lesson_id: {
|
|
type: DataTypes.UUID,
|
|
allowNull: false,
|
|
comment: 'ID bài học'
|
|
},
|
|
component_id: {
|
|
type: DataTypes.STRING(50),
|
|
allowNull: false,
|
|
comment: 'ID component từ content_json.components[].id'
|
|
},
|
|
component_type: {
|
|
type: DataTypes.STRING(50),
|
|
comment: 'Loại component: story_game, game, results_board, leaderboard'
|
|
},
|
|
|
|
// Progress tracking
|
|
status: {
|
|
type: DataTypes.ENUM('not_started', 'in_progress', 'completed'),
|
|
defaultValue: 'not_started',
|
|
comment: 'Trạng thái tiến độ'
|
|
},
|
|
started_at: {
|
|
type: DataTypes.DATE,
|
|
comment: 'Thời gian bắt đầu'
|
|
},
|
|
completed_at: {
|
|
type: DataTypes.DATE,
|
|
comment: 'Thời gian hoàn thành'
|
|
},
|
|
|
|
// Results (cho game/quiz components)
|
|
score: {
|
|
type: DataTypes.INTEGER,
|
|
comment: 'Điểm số đạt được'
|
|
},
|
|
max_score: {
|
|
type: DataTypes.INTEGER,
|
|
comment: 'Điểm tối đa'
|
|
},
|
|
accuracy: {
|
|
type: DataTypes.DECIMAL(5, 2),
|
|
comment: 'Độ chính xác (%)'
|
|
},
|
|
time_spent: {
|
|
type: DataTypes.INTEGER,
|
|
comment: 'Thời gian làm bài (giây)'
|
|
},
|
|
attempts: {
|
|
type: DataTypes.INTEGER,
|
|
defaultValue: 0,
|
|
comment: 'Số lần thử'
|
|
},
|
|
|
|
// Detailed results
|
|
results_data: {
|
|
type: DataTypes.JSON,
|
|
comment: 'Chi tiết kết quả: câu trả lời, achievements, etc.'
|
|
},
|
|
|
|
created_at: {
|
|
type: DataTypes.DATE,
|
|
allowNull: false,
|
|
defaultValue: DataTypes.NOW
|
|
},
|
|
updated_at: {
|
|
type: DataTypes.DATE,
|
|
allowNull: false,
|
|
defaultValue: DataTypes.NOW
|
|
}
|
|
}, {
|
|
tableName: 'lesson_component_progress',
|
|
timestamps: true,
|
|
underscored: true,
|
|
indexes: [
|
|
{ fields: ['user_id'] },
|
|
{ fields: ['lesson_id'] },
|
|
{ fields: ['status'] },
|
|
{ fields: ['user_id', 'lesson_id', 'component_id'], unique: true }
|
|
]
|
|
});
|
|
|
|
module.exports = LessonComponentProgress;
|