question.js 942 B

1234567891011121314151617181920212223242526
  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 questionSchema = {
  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. const schema = new Schema(questionSchema, { toJSON: { virtuals: true } });
  17. schema.index({ id: 1 });
  18. schema.plugin(metaPlugin);
  19. module.exports = app => {
  20. const { mongoose } = app;
  21. return mongoose.model('Question', schema, 'question');
  22. };