notice.js 1.0 KB

12345678910111213141516171819202122232425262728
  1. 'use strict';
  2. const Schema = require('mongoose').Schema;
  3. const metaPlugin = require('naf-framework-mongoose-free/lib/model/meta-plugin');
  4. // 系统通知表
  5. const notice = {
  6. customer: { type: String, required: true, zh: '用户', ref: 'User.User' }, //
  7. source: { type: String, required: false, zh: '消息来源' }, // 字典:notice_source
  8. source_id: { type: String, required: false, zh: '来源id' }, //
  9. time: { type: String, required: false, zh: '发送时间' }, //
  10. content: { type: String, required: false, zh: '内容' }, //
  11. status: { type: String, required: false, default: '0', zh: '状态' }, // 字典:notice_status
  12. };
  13. const schema = new Schema(notice, { toJSON: { getters: true, virtuals: true } });
  14. schema.index({ id: 1 });
  15. schema.index({ 'meta.createdAt': 1 });
  16. schema.index({ customer: 1 });
  17. schema.index({ source: 1 });
  18. schema.index({ source_id: 1 });
  19. schema.index({ time: 1 });
  20. schema.index({ status: 1 });
  21. schema.plugin(metaPlugin);
  22. module.exports = app => {
  23. const { mongoose } = app;
  24. return mongoose.model('Notice', schema, 'notice');
  25. };