|
@@ -0,0 +1,23 @@
|
|
|
+'use strict';
|
|
|
+const Schema = require('mongoose').Schema;
|
|
|
+const moment = require('moment');
|
|
|
+const metaPlugin = require('naf-framework-mongoose/lib/model/meta-plugin');
|
|
|
+const { ObjectId } = require('mongoose').Types;
|
|
|
+// 问卷回答表
|
|
|
+const answer = {
|
|
|
+ questionnaire_id: { type: ObjectId }, // 问卷id
|
|
|
+ answer: { type: Array }, // 答案
|
|
|
+ user_id: { type: ObjectId },
|
|
|
+ remark: { type: String, maxLength: 200 },
|
|
|
+ create_time: { type: String, default: moment(new Date()).format('YYYY-MM-DD HH:mm:ss') },
|
|
|
+};
|
|
|
+const schema = new Schema(answer, { toJSON: { virtuals: true } });
|
|
|
+schema.index({ id: 1 });
|
|
|
+schema.index({ questionnaire_id: 1 });
|
|
|
+schema.index({ user_id: 1 });
|
|
|
+schema.index({ 'meta.createdAt': 1 });
|
|
|
+schema.plugin(metaPlugin);
|
|
|
+module.exports = app => {
|
|
|
+ const { mongoose } = app;
|
|
|
+ return mongoose.model('Answer', schema, 'answer');
|
|
|
+};
|