eliminate.js 2.4 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 eliminate = {
  6. match_id: { type: String, required: false, zh: '赛事i', ref: 'Race.Match' }, //
  7. group_id: { type: String, required: false, zh: '组别id', ref: 'Race.MatchGroup' }, //
  8. project_id: { type: String, required: false, zh: '项目id', ref: 'Race.MatchProject' }, //
  9. address_id: { type: String, required: false, zh: '场地id', ref: 'Race.MatchAddress' }, //
  10. referee_id: { type: String, required: false, zh: '裁判id', ref: 'Race.User' }, //
  11. match_time: { type: String, required: false, zh: '比赛时间' }, //
  12. player_type: { type: String, required: false, zh: '选手类型' }, // 0:单打,user;1:双打,teamApply
  13. player_one: { type: String, required: false, zh: '选手一' }, //
  14. player_one_score: { type: Number, required: false, zh: '选手一比分' }, //
  15. player_one_node: { type: String, required: false, zh: '选手一节点' }, //
  16. player_two: { type: String, required: false, zh: '选手二' }, //
  17. player_two_score: { type: Number, required: false, zh: '选手二比分' }, //
  18. player_two_node: { type: String, required: false, zh: '选手二节点' }, //
  19. is_change: { type: String, required: false, default: '0', zh: '是否交换' }, //
  20. status: { type: String, required: false, default: '0', zh: '赛程状态' }, // 0:待开始,1:已开始,2:已结束
  21. winner: { type: String, required: false, zh: '胜者' }, //
  22. };
  23. const schema = new Schema(eliminate, { toJSON: { getters: true, virtuals: true } });
  24. schema.index({ id: 1 });
  25. schema.index({ 'meta.createdAt': 1 });
  26. schema.index({ match_id: 1 });
  27. schema.index({ group_id: 1 });
  28. schema.index({ project_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('Eliminate', schema, 'eliminate');
  45. } else {
  46. const { mongoose } = app;
  47. model = mongoose.model('Eliminate', schema, 'eliminate');
  48. }
  49. return model;
  50. };