notice.js 1.1 KB

123456789101112131415161718192021222324252627282930
  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. shop: { type: String, required: false, zh: '店铺id' }, //
  10. time: { type: String, required: false, zh: '发送时间' }, //
  11. content: { type: String, required: false, zh: '内容' }, //
  12. status: { type: String, required: false, default: '0', zh: '状态' }, // 字典:notice_status
  13. };
  14. const schema = new Schema(notice, { toJSON: { getters: true, virtuals: true } });
  15. schema.index({ id: 1 });
  16. schema.index({ 'meta.createdAt': 1 });
  17. schema.index({ customer: 1 });
  18. schema.index({ source: 1 });
  19. schema.index({ source_id: 1 });
  20. schema.index({ shop: 1 });
  21. schema.index({ time: 1 });
  22. schema.index({ status: 1 });
  23. schema.plugin(metaPlugin);
  24. module.exports = app => {
  25. const { mongoose } = app;
  26. return mongoose.model('Notice', schema, 'notice');
  27. };