questionnaire.js 773 B

12345678910111213141516171819202122232425
  1. 'use strict';
  2. const Schema = require('mongoose').Schema;
  3. const metaPlugin = require('naf-framework-mongoose/lib/model/meta-plugin');
  4. // 问题code表
  5. const questions = new Schema({
  6. questionid: { type: String, required: false, maxLength: 200 }, // 序号
  7. });
  8. // 问卷表
  9. const QuestionnaireSchema = {
  10. name: { type: String, required: true, maxLength: 200 }, // 问卷名称
  11. num: { type: String, required: true, maxLength: 200 }, // 序号
  12. question: { type: [ questions ], select: true }, // 问题code
  13. };
  14. const schema = new Schema(QuestionnaireSchema, { toJSON: { virtuals: true } });
  15. schema.index({ id: 1 });
  16. schema.plugin(metaPlugin);
  17. module.exports = app => {
  18. const { mongoose } = app;
  19. return mongoose.model('Questionnaire', schema, 'questionnaire');
  20. };