101 lines
2.2 KiB
JavaScript
101 lines
2.2 KiB
JavaScript
const { DataTypes } = require('sequelize');
|
|
const { sequelize } = require('../config/database');
|
|
|
|
/**
|
|
* Grades Model - Điểm số chi tiết của học sinh
|
|
* Bảng lớn nhất trong hệ thống
|
|
*/
|
|
const Grade = sequelize.define('grades', {
|
|
id: {
|
|
type: DataTypes.UUID,
|
|
defaultValue: DataTypes.UUIDV4,
|
|
primaryKey: true,
|
|
},
|
|
grade_item_id: {
|
|
type: DataTypes.UUID,
|
|
allowNull: false,
|
|
references: {
|
|
model: 'grade_items',
|
|
key: 'id',
|
|
},
|
|
comment: 'ID cột điểm',
|
|
},
|
|
student_id: {
|
|
type: DataTypes.UUID,
|
|
allowNull: false,
|
|
comment: 'ID học sinh',
|
|
},
|
|
class_id: {
|
|
type: DataTypes.UUID,
|
|
allowNull: false,
|
|
references: {
|
|
model: 'classes',
|
|
key: 'id',
|
|
},
|
|
comment: 'ID lớp học',
|
|
},
|
|
score: {
|
|
type: DataTypes.DECIMAL(5, 2),
|
|
comment: 'Điểm số',
|
|
validate: {
|
|
min: 0,
|
|
max: 100,
|
|
},
|
|
},
|
|
grade_level: {
|
|
type: DataTypes.STRING(5),
|
|
comment: 'Xếp loại (A, B, C, D, F)',
|
|
},
|
|
comment: {
|
|
type: DataTypes.TEXT,
|
|
comment: 'Nhận xét của giáo viên',
|
|
},
|
|
graded_by: {
|
|
type: DataTypes.UUID,
|
|
comment: 'ID giáo viên chấm điểm',
|
|
},
|
|
graded_at: {
|
|
type: DataTypes.DATE,
|
|
comment: 'Thời gian chấm điểm',
|
|
},
|
|
is_published: {
|
|
type: DataTypes.BOOLEAN,
|
|
defaultValue: false,
|
|
comment: 'Đã công bố cho học sinh/phụ huynh',
|
|
},
|
|
published_at: {
|
|
type: DataTypes.DATE,
|
|
comment: 'Thời gian công bố',
|
|
},
|
|
is_locked: {
|
|
type: DataTypes.BOOLEAN,
|
|
defaultValue: false,
|
|
comment: 'Khóa điểm, không cho sửa',
|
|
},
|
|
created_at: {
|
|
type: DataTypes.DATE,
|
|
allowNull: false,
|
|
defaultValue: DataTypes.NOW,
|
|
},
|
|
updated_at: {
|
|
type: DataTypes.DATE,
|
|
allowNull: false,
|
|
defaultValue: DataTypes.NOW,
|
|
},
|
|
}, {
|
|
tableName: 'grades',
|
|
timestamps: true,
|
|
underscored: true,
|
|
indexes: [
|
|
{ fields: ['grade_item_id', 'student_id'], unique: true },
|
|
{ fields: ['student_id', 'class_id'] },
|
|
{ fields: ['class_id'] },
|
|
{ fields: ['graded_by'] },
|
|
{ fields: ['is_published'] },
|
|
{ fields: ['created_at'] },
|
|
],
|
|
comment: 'Bảng điểm chi tiết - Dữ liệu lớn nhất hệ thống',
|
|
});
|
|
|
|
module.exports = Grade;
|