questionnaire.js 947 B

1234567891011121314151617181920212223242526
  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 questionnaire = {
  8. title: { type: String },
  9. user_id: { type: ObjectId },
  10. questions: { type: Array, select: false },
  11. brief: { type: String }, // 简介
  12. column: { type: String }, // 简介
  13. remark: { type: String, maxLength: 200 },
  14. create_time: { type: String, default: moment(new Date()).format('YYYY-MM-DD HH:mm:ss') },
  15. };
  16. const schema = new Schema(questionnaire, { toJSON: { virtuals: true } });
  17. schema.index({ id: 1 });
  18. schema.index({ title: 1 });
  19. schema.index({ column: 1 });
  20. schema.index({ questions: 1 });
  21. schema.index({ 'meta.createdAt': 1 });
  22. schema.plugin(metaPlugin);
  23. module.exports = app => {
  24. const { mongoose } = app;
  25. return mongoose.model('Questionnaire', schema, 'questionnaire');
  26. };