task.js 1.3 KB

1234567891011121314151617181920212223242526272829303132333435
  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. });
  16. // 作业表
  17. const TaskSchema = {
  18. code: { type: String, required: true, maxLength: 200 }, // 科目代码
  19. name: { type: String, required: true, maxLength: 500 }, // 科目名称
  20. title: { type: String, required: true, maxLength: 500 }, // 标题
  21. status: { type: String, required: false, maxLength: 200 }, // 状态,0-弃用,1-正常
  22. question: { type: [ questionInfo ], select: true }, // 问题
  23. };
  24. const schema = new Schema(TaskSchema, { toJSON: { virtuals: true } });
  25. schema.index({ id: 1 });
  26. schema.plugin(metaPlugin);
  27. module.exports = app => {
  28. const { mongoose } = app;
  29. return mongoose.model('Task', schema, 'task');
  30. };