question.js 929 B

12345678910111213141516171819202122232425
  1. 'use strict';
  2. const Schema = require('mongoose').Schema;
  3. const moment = require('moment');
  4. const metaPlugin = require('naf-framework-mongoose/lib/model/meta-plugin');
  5. const { ObjectId } = require('mongoose').Types;
  6. // 问卷题目表
  7. const question = {
  8. title: { type: String },
  9. type: { type: String }, // 类型:0=>单选;1=>多选;2=>简答
  10. selects: { type: Array }, // 选项
  11. user_id: { type: ObjectId }, // 所属用户
  12. remark: { type: String, maxLength: 200 },
  13. create_time: { type: String, default: moment(new Date()).format('YYYY-MM-DD HH:mm:ss') },
  14. };
  15. const schema = new Schema(question, { toJSON: { virtuals: true } });
  16. schema.index({ id: 1 });
  17. schema.index({ title: 1 });
  18. schema.index({ user_id: 1 });
  19. schema.index({ type: 1 });
  20. schema.index({ 'meta.createdAt': 1 });
  21. schema.plugin(metaPlugin);
  22. module.exports = app => {
  23. const { mongoose } = app;
  24. return mongoose.model('Question', schema, 'question');
  25. };