update
This commit is contained in:
101
models/Game.js
Normal file
101
models/Game.js
Normal file
@@ -0,0 +1,101 @@
|
||||
const { DataTypes } = require('sequelize');
|
||||
const { sequelize } = require('../config/database');
|
||||
|
||||
/**
|
||||
* Game Model - Trò chơi giáo dục
|
||||
* Các game engine/template để render nội dung học tập
|
||||
* Một game có thể render nhiều lesson khác nhau có cùng type
|
||||
*/
|
||||
const Game = sequelize.define('games', {
|
||||
id: {
|
||||
type: DataTypes.UUID,
|
||||
defaultValue: DataTypes.UUIDV4,
|
||||
primaryKey: true
|
||||
},
|
||||
title: {
|
||||
type: DataTypes.STRING(200),
|
||||
allowNull: false,
|
||||
comment: 'Tên trò chơi'
|
||||
},
|
||||
description: {
|
||||
type: DataTypes.TEXT,
|
||||
comment: 'Mô tả về trò chơi'
|
||||
},
|
||||
url: {
|
||||
type: DataTypes.TEXT,
|
||||
allowNull: false,
|
||||
comment: 'URL của game (HTML5 game, Unity WebGL, etc.)'
|
||||
},
|
||||
thumbnail: {
|
||||
type: DataTypes.TEXT,
|
||||
comment: 'URL ảnh thumbnail'
|
||||
},
|
||||
type: {
|
||||
type: DataTypes.STRING(50),
|
||||
allowNull: false,
|
||||
comment: 'Loại game: counting_quiz, math_game, word_puzzle, etc. - Must match lesson content_json.type'
|
||||
},
|
||||
config: {
|
||||
type: DataTypes.JSON,
|
||||
comment: 'Cấu hình game: controls, settings, features, etc.'
|
||||
},
|
||||
is_active: {
|
||||
type: DataTypes.BOOLEAN,
|
||||
defaultValue: true,
|
||||
comment: 'Game có sẵn sàng để sử dụng không'
|
||||
},
|
||||
is_premium: {
|
||||
type: DataTypes.BOOLEAN,
|
||||
defaultValue: false,
|
||||
comment: 'Yêu cầu premium để chơi'
|
||||
},
|
||||
min_grade: {
|
||||
type: DataTypes.INTEGER,
|
||||
comment: 'Cấp lớp tối thiểu (1-12)'
|
||||
},
|
||||
max_grade: {
|
||||
type: DataTypes.INTEGER,
|
||||
comment: 'Cấp lớp tối đa (1-12)'
|
||||
},
|
||||
difficulty_level: {
|
||||
type: DataTypes.ENUM('easy', 'medium', 'hard'),
|
||||
comment: 'Độ khó'
|
||||
},
|
||||
play_count: {
|
||||
type: DataTypes.INTEGER,
|
||||
defaultValue: 0,
|
||||
comment: 'Số lần đã chơi'
|
||||
},
|
||||
rating: {
|
||||
type: DataTypes.DECIMAL(3, 2),
|
||||
comment: 'Đánh giá (0.00 - 5.00)'
|
||||
},
|
||||
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: 'games',
|
||||
timestamps: true,
|
||||
underscored: true,
|
||||
indexes: [
|
||||
{ fields: ['type'] },
|
||||
{ fields: ['is_active'] },
|
||||
{ fields: ['is_premium'] },
|
||||
{ fields: ['display_order'] },
|
||||
{ fields: ['difficulty_level'] },
|
||||
],
|
||||
});
|
||||
|
||||
module.exports = Game;
|
||||
Reference in New Issue
Block a user