This commit is contained in:
silverpro89
2026-01-26 20:23:08 +07:00
parent 53d97ba5db
commit 2c7b4675a7
49 changed files with 12668 additions and 1 deletions

84
models/Grammar.js Normal file
View File

@@ -0,0 +1,84 @@
const { DataTypes } = require('sequelize');
const { sequelize } = require('../config/database');
const Grammar = sequelize.define('Grammar', {
id: {
type: DataTypes.UUID,
defaultValue: DataTypes.UUIDV4,
primaryKey: true
},
grammar_code: {
type: DataTypes.STRING(100),
allowNull: false,
unique: true,
comment: 'Unique identifier for grammar rule (e.g., "gram-001-present-cont")'
},
title: {
type: DataTypes.STRING(200),
allowNull: false,
comment: 'Grammar rule name (e.g., "Present Continuous")'
},
translation: {
type: DataTypes.STRING(200),
allowNull: true,
comment: 'Vietnamese translation'
},
// GENERATIVE LOGIC
structure: {
type: DataTypes.JSON,
allowNull: false,
defaultValue: {},
comment: 'Formula and pattern_logic for sentence generation. Structure: { formula: string, pattern_logic: array }'
},
// METADATA
instructions: {
type: DataTypes.JSON,
allowNull: true,
defaultValue: {},
comment: 'Instructions and hints. Structure: { vi: string, hint: string }'
},
// ATTRIBUTES
difficulty_score: {
type: DataTypes.INTEGER,
allowNull: true,
defaultValue: 1,
validate: {
min: 1,
max: 10
},
comment: 'Difficulty level from 1 (easiest) to 10 (hardest)'
},
category: {
type: DataTypes.STRING(100),
allowNull: true,
comment: 'Grammar category (e.g., "Tenses", "Modal Verbs", "Questions")'
},
tags: {
type: DataTypes.JSON,
allowNull: true,
defaultValue: [],
comment: 'Array of tags for categorization'
},
// STATUS
is_active: {
type: DataTypes.BOOLEAN,
allowNull: false,
defaultValue: true,
comment: 'Soft delete flag'
}
}, {
tableName: 'grammars',
timestamps: true,
indexes: [
{ fields: ['grammar_code'], unique: true },
{ fields: ['category'] },
{ fields: ['difficulty_score'] },
{ fields: ['is_active'] }
]
});
module.exports = Grammar;