matchTeamGroup.js 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839
  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_team_group = {
  6. match_id: { type: String, required: true, zh: '赛事id', ref: 'Race.Match', getProp: [ 'name' ] }, // 比赛信息中的名称
  7. group_id: { type: String, required: true, zh: '组别id', ref: 'Race.MatchGroup', getProp: [ 'name' ] }, // 赛事组别中的名称
  8. project_id: { type: String, required: true, zh: '项目id', ref: 'Race.MatchProject', getProp: [ 'name' ] }, // 组内项目中的名称
  9. name: { type: String, required: true, zh: '分组名称' }, //
  10. person_type: { type: String, required: false, zh: '人员类型' }, // 单打:user;双打:teamApply
  11. person: { type: Array, required: false, zh: '组内人员' }, // refPath: 'person_type'
  12. remark: { type: String, required: false, zh: '备注' }, //
  13. rise: { type: String, required: true, zh: '取前几' }, //
  14. };
  15. const schema = new Schema(match_team_group, { toJSON: { getters: true, virtuals: true } });
  16. schema.index({ id: 1 });
  17. schema.index({ 'meta.createdAt': 1 });
  18. schema.index({ match_id: 1 });
  19. schema.index({ group_id: 1 });
  20. schema.index({ project_id: 1 });
  21. schema.index({ name: 1 });
  22. schema.index({ rise: 1 });
  23. schema.plugin(metaPlugin);
  24. const source = 'race';
  25. module.exports = app => {
  26. const is_multiple = app.mongooseDB.clients;
  27. let model;
  28. if (is_multiple) {
  29. const conn = app.mongooseDB.get(source);
  30. model = conn.model('MatchTeamGroup', schema, 'MatchTeamGroup');
  31. } else {
  32. const { mongoose } = app;
  33. model = mongoose.model('MatchTeamGroup', schema, 'MatchTeamGroup');
  34. }
  35. return model;
  36. };