'use strict'; const Schema = require('mongoose').Schema; const moment = require('moment'); const metaPlugin = require('naf-framework-mongoose/lib/model/meta-plugin'); const { Secret } = require('naf-framework-mongoose/lib/model/schema'); const { ObjectId } = require('mongoose').Types; // 通知管理表 const notice = { title: { type: String, required: true, maxLength: 500 }, // 标题 source: { type: String, required: false, maxLength: 500 }, // 来源 content: { type: String, required: false, maxLength: 500 }, // 内容 isenable: { type: String, required: false, maxLength: 500, default: '0' }, // 是否启用(0:未启用 1:启用 2:禁用) user_id: { type: ObjectId, required: false, maxLength: 500 }, // 发布人id code: { type: String, required: false, maxLength: 500 }, // 所属机构代码 remark: { type: String, maxLength: 200 }, create_time: { type: String, default: moment().format('YYYY-MM-DD HH:mm:ss') }, // 发布时间 }; const schema = new Schema(notice, { toJSON: { virtuals: true } }); schema.index({ id: 1 }); schema.index({ title: 1 }); schema.index({ user_id: 1 }); schema.index({ code: 1 }); schema.index({ 'meta.createdAt': 1 }); schema.plugin(metaPlugin); module.exports = app => { const { mongoose } = app; return mongoose.model('Notice', schema, 'notice'); };