matchSmallGroupSchedule.js 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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_small_group_schedule = {
  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. team_id: { type: String, required: true, zh: '小组id', ref: 'Race.MatchTeamGroup', getProp: [ 'name' ] }, // 小组赛组设置中的name
  10. address_id: { type: String, required: true, zh: '场地id', ref: 'Race.MatchAddress', getProp: [ 'name' ] }, // 赛事场地中name
  11. referee_id: { type: String, required: true, zh: '裁判id', ref: 'Race.User', getProp: [ 'name' ] }, // 用户表中的name
  12. match_time: { type: String, required: true, zh: '比赛时间' }, //
  13. player_type: { type: String, required: true, zh: '选手类型' }, // 0:单打,user;1:双打,teamApply
  14. player_one: { type: String, required: true, zh: '选手一' }, // , refPath: 'player_type'
  15. player_one_score: { type: String, required: false, zh: '选手一比分' }, //
  16. player_two: { type: String, required: true, zh: '选手二' }, // , refPath: 'player_type'
  17. player_two_score: { type: String, required: false, zh: '选手二比分' }, //
  18. is_change: { type: String, required: false, default: '0', zh: '是否交换' }, // 0:未交换,1:已交换
  19. status: { type: String, required: false, default: '0', zh: '赛程状态' }, // 0:待开始,1:已开始,2:已结束
  20. winner: { type: String, required: false, zh: '胜者' }, //
  21. };
  22. const schema = new Schema(match_small_group_schedule, { toJSON: { getters: true, virtuals: true } });
  23. schema.index({ id: 1 });
  24. schema.index({ 'meta.createdAt': 1 });
  25. schema.index({ match_id: 1 });
  26. schema.index({ group_id: 1 });
  27. schema.index({ project_id: 1 });
  28. schema.index({ team_id: 1 });
  29. schema.index({ address_id: 1 });
  30. schema.index({ referee_id: 1 });
  31. schema.index({ match_time: 1 });
  32. schema.index({ player_type: 1 });
  33. schema.index({ player_one: 1 });
  34. schema.index({ player_two: 1 });
  35. schema.index({ is_change: 1 });
  36. schema.index({ status: 1 });
  37. schema.plugin(metaPlugin);
  38. const source = 'race';
  39. module.exports = app => {
  40. const is_multiple = app.mongooseDB.clients;
  41. let model;
  42. if (is_multiple) {
  43. const conn = app.mongooseDB.get(source);
  44. model = conn.model('Msgs', schema, 'msgs');
  45. } else {
  46. const { mongoose } = app;
  47. model = mongoose.model('Msgs', schema, 'msgs');
  48. }
  49. return model;
  50. };