1234567891011121314151617181920212223242526 |
- '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 questionnaire = {
- title: { type: String },
- user_id: { type: ObjectId },
- questions: { type: Array, select: false },
- brief: { type: String }, // 简介
- column: { type: String }, // 简介
- remark: { type: String, maxLength: 200 },
- create_time: { type: String, default: moment(new Date()).format('YYYY-MM-DD HH:mm:ss') },
- };
- const schema = new Schema(questionnaire, { toJSON: { virtuals: true } });
- schema.index({ id: 1 });
- schema.index({ title: 1 });
- schema.index({ column: 1 });
- schema.index({ questions: 1 });
- schema.index({ 'meta.createdAt': 1 });
- schema.plugin(metaPlugin);
- module.exports = app => {
- const { mongoose } = app;
- return mongoose.model('Questionnaire', schema, 'questionnaire');
- };
|