answer.js 1.1 KB

1234567891011121314151617181920212223242526272829303132
  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 answer = {
  8. questionnaire_id: { type: ObjectId }, // 问卷id
  9. answer: { type: Array }, // 答案
  10. user_id: { type: ObjectId },//用户id
  11. phone: { type: String },//电话
  12. contacts: { type: String },//联系人
  13. company: { type: String },//企业名称
  14. address: { type: String },//联系地址
  15. attribute: { type: String },//企业属性
  16. category: { type: String },//产品类别
  17. remark: { type: String, maxLength: 200 },
  18. create_time: {
  19. type: String,
  20. default: moment(new Date()).format("YYYY-MM-DD HH:mm:ss"),
  21. },
  22. };
  23. const schema = new Schema(answer, { toJSON: { virtuals: true } });
  24. schema.index({ id: 1 });
  25. schema.index({ questionnaire_id: 1 });
  26. schema.index({ user_id: 1 });
  27. schema.index({ 'meta.createdAt': 1 });
  28. schema.plugin(metaPlugin);
  29. module.exports = app => {
  30. const { mongoose } = app;
  31. return mongoose.model('Answer', schema, 'answer');
  32. };