questionnaire.js 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738
  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 = {
  11. type: { type: String, required: true, maxLength: 200 }, // 类型,0-单选,1-多选,2-问答
  12. topic: { type: String, required: true, maxLength: 500 }, // 题目
  13. status: { type: String, required: false, maxLength: 200 }, // 状态,0-弃用,1-正常
  14. option: { type: [ optionInfo ], select: true }, // 选项
  15. };
  16. // 问卷表
  17. const QuestionnaireSchema = {
  18. name: { type: String, required: true, maxLength: 200 }, // 问卷名称
  19. num: { type: String, required: true, maxLength: 200 }, // 序号
  20. type: { type: String, required: true, maxLength: 200 }, // 类型,0-常用问卷,1-非常用问卷,2-教师问卷
  21. status: { type: String, required: true, maxLength: 200, default: '0' }, // 状态,0-草稿,1-发布,2-禁用
  22. question: { type: [ questionInfo ], required: false, select: true }, // 问卷
  23. };
  24. const schema = new Schema(QuestionnaireSchema, { toJSON: { virtuals: true } });
  25. schema.index({ id: 1 });
  26. schema.index({ type: 1 });
  27. schema.plugin(metaPlugin);
  28. module.exports = app => {
  29. const { mongoose } = app;
  30. return mongoose.model('Questionnaire', schema, 'questionnaire');
  31. };