matchGroup.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. const source = 'race';
  5. // 赛事组别
  6. const match_group = {
  7. match_id: { type: String, required: true, zh: '赛事id', ref: 'match', getProp: [ 'name' ] }, // 比赛信息中的比赛名称
  8. name: { type: String, required: true, zh: '名称' }, //
  9. age: { type: String, required: false, zh: '年龄限制' }, //
  10. explain: { type: String, required: false, zh: '说明' }, //
  11. };
  12. const schema = new Schema(match_group, { toJSON: { getters: true, virtuals: true } });
  13. schema.index({ id: 1 });
  14. schema.index({ 'meta.createdAt': 1 });
  15. schema.index({ match_id: 1 });
  16. schema.index({ name: 1 });
  17. schema.plugin(metaPlugin);
  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('MatchGroup', schema, 'matchGroup');
  24. } else {
  25. const { mongoose } = app;
  26. model = mongoose.model('MatchGroup', schema, 'matchGroup');
  27. }
  28. return model;
  29. };