task.js 1.4 KB

123456789101112131415161718192021222324252627282930313233343536
  1. 'use strict';
  2. const Schema = require('mongoose').Schema;
  3. const metaPlugin = require('naf-framework-mongoose/lib/model/meta-plugin');
  4. // 选项详情
  5. const optionInfo = new Schema({
  6. number: { type: String, required: false, maxLength: 200 }, // 序号
  7. opname: { type: String, required: false, maxLength: 200 }, // 名称
  8. });
  9. // 问题详情
  10. const questionInfo = new Schema({
  11. type: { type: String, required: false, maxLength: 200 }, // 类型,0-单选,1-多选,2-问答
  12. topic: { type: String, required: false, maxLength: 500 }, // 题目
  13. answer: { type: String, required: false, maxLength: 500 }, // 答案
  14. option: { type: [ optionInfo ], select: true }, // 选项
  15. score: { type: String, required: false, maxLength: 500 }, // 分数
  16. });
  17. // 作业表
  18. const TaskSchema = {
  19. code: { type: String, required: true, maxLength: 200 }, // 科目代码
  20. name: { type: String, required: true, maxLength: 500 }, // 科目名称
  21. title: { type: String, required: true, maxLength: 500 }, // 标题
  22. status: { type: String, required: false, maxLength: 200 }, // 状态,0-弃用,1-正常
  23. question: { type: [ questionInfo ], select: true }, // 问题
  24. };
  25. const schema = new Schema(TaskSchema, { toJSON: { virtuals: true } });
  26. schema.index({ id: 1 });
  27. schema.plugin(metaPlugin);
  28. module.exports = app => {
  29. const { mongoose } = app;
  30. return mongoose.model('Task', schema, 'task');
  31. };