Files
competition-website/app/model/examQuestion.js

84 lines
1.8 KiB
JavaScript
Raw Normal View History

'use strict';
/**
* 试卷题目模型 - ExamQuestion
*
* 存储各参赛组别的试卷题目,按组别区分,支持排序。
* 表名:exam_questions
*/
module.exports = app => {
const { STRING, TEXT, INTEGER, DATE } = app.Sequelize;
const ExamQuestion = app.model.define('exam_question', {
// 主键 ID,自增
id: {
type: INTEGER,
primaryKey: true,
autoIncrement: true,
comment: '题目唯一标识',
},
// 所属组别:zhongzhi/gaozhi/benke/jiaoshi
group: {
type: STRING(20),
allowNull: false,
comment: '题目所属组别',
validate: {
isIn: [['zhongzhi', 'gaozhi', 'benke', 'jiaoshi']],
},
},
// 题目标题
title: {
type: STRING(200),
allowNull: false,
comment: '题目标题',
},
// 题目详细内容/描述
content: {
type: TEXT,
allowNull: false,
comment: '题目内容描述',
},
// 题目分值
score: {
type: INTEGER,
allowNull: false,
comment: '题目分值',
},
// 排序序号(决定题目在试卷中的展示顺序)
sort_order: {
type: INTEGER,
allowNull: false,
defaultValue: 0,
comment: '排序序号',
},
// 创建时间
created_at: {
type: DATE,
allowNull: false,
defaultValue: app.Sequelize.literal('CURRENT_TIMESTAMP'),
comment: '创建时间',
},
// 更新时间
updated_at: {
type: DATE,
allowNull: false,
defaultValue: app.Sequelize.literal('CURRENT_TIMESTAMP'),
comment: '更新时间',
},
}, {
tableName: 'exam_questions',
timestamps: false,
underscored: true,
indexes: [
{
fields: ['group'],
},
{
fields: ['group', 'sort_order'],
},
],
});
return ExamQuestion;
};