notice.js 1.3 KB

12345678910111213141516171819202122232425262728
  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 { Secret } = require('naf-framework-mongoose/lib/model/schema');
  6. const { ObjectId } = require('mongoose').Types;
  7. // 通知管理表
  8. const notice = {
  9. title: { type: String, required: true, maxLength: 500 }, // 标题
  10. source: { type: String, required: false, maxLength: 500 }, // 来源
  11. content: { type: String, required: false, maxLength: 500 }, // 内容
  12. isenable: { type: String, required: false, maxLength: 500, default: '0' }, // 是否启用(0:未启用 1:启用 2:禁用)
  13. user_id: { type: ObjectId, required: false, maxLength: 500 }, // 发布人id
  14. code: { type: String, required: false, maxLength: 500 }, // 所属机构代码
  15. remark: { type: String, maxLength: 200 },
  16. create_time: { type: String, default: moment().format('YYYY-MM-DD HH:mm:ss') }, // 发布时间
  17. };
  18. const schema = new Schema(notice, { toJSON: { virtuals: true } });
  19. schema.index({ id: 1 });
  20. schema.index({ title: 1 });
  21. schema.index({ user_id: 1 });
  22. schema.index({ code: 1 });
  23. schema.index({ 'meta.createdAt': 1 });
  24. schema.plugin(metaPlugin);
  25. module.exports = app => {
  26. const { mongoose } = app;
  27. return mongoose.model('Notice', schema, 'notice');
  28. };