'use strict'; const Schema = require('mongoose').Schema; const metaPlugin = require('naf-framework-mongoose/lib/model/meta-plugin'); // 选项详情 const optionInfo = new Schema({ number: { type: String, required: false, maxLength: 200 }, // 序号 opname: { type: String, required: false, maxLength: 200 }, // 名称 }); // 问卷题库表 const questionSchema = { type: { type: String, required: true, maxLength: 200 }, // 类型,0-单选,1-多选,2-问答 topic: { type: String, required: true, maxLength: 500 }, // 题目 status: { type: String, required: false, maxLength: 200 }, // 状态,0-弃用,1-正常 option: { type: [ optionInfo ], select: true }, // 选项 }; const schema = new Schema(questionSchema, { toJSON: { virtuals: true } }); schema.index({ id: 1 }); schema.plugin(metaPlugin); module.exports = app => { const { mongoose } = app; return mongoose.model('Question', schema, 'question'); };