matchAddress.js 1.1 KB

1234567891011121314151617181920212223242526272829303132
  1. 'use strict';
  2. const Schema = require('mongoose').Schema;
  3. const metaPlugin = require('naf-framework-mongoose-free/lib/model/meta-plugin');
  4. // 赛事场地
  5. const match_address = {
  6. belong_id: { type: String, required: true, zh: '归属id', ref: 'Race.User', getProp: [ 'name' ] }, // 用户表中的名称
  7. name: { type: String, required: true, zh: '名称' }, //
  8. remark: { type: String, required: false, zh: '备注' }, //
  9. is_use: { type: String, required: false, default: '0', zh: '是否使用' }, // 0:启用,1:禁用
  10. };
  11. const schema = new Schema(match_address, { toJSON: { getters: true, virtuals: true } });
  12. schema.index({ id: 1 });
  13. schema.index({ 'meta.createdAt': 1 });
  14. schema.index({ belong_id: 1 });
  15. schema.index({ name: 1 });
  16. schema.plugin(metaPlugin);
  17. const source = 'race';
  18. module.exports = app => {
  19. const is_multiple = app.mongooseDB.clients;
  20. let model;
  21. if (is_multiple) {
  22. const conn = app.mongooseDB.get(source);
  23. model = conn.model('MatchAddress', schema, 'matchAddress');
  24. } else {
  25. const { mongoose } = app;
  26. model = mongoose.model('MatchAddress', schema, 'matchAddress');
  27. }
  28. return model;
  29. };