lrf 2 years ago
parent
commit
64a9fe9766

+ 2 - 2
app/model/race/matchSmallGroupSchedule.js

@@ -12,9 +12,9 @@ const match_small_group_schedule = {
   referee_id: { type: String, required: true, zh: '裁判id', ref: 'Race.User', getProp: [ 'name' ] }, // 用户表中的name
   match_time: { type: String, required: true, zh: '比赛时间' }, //
   player_type: { type: String, required: true, zh: '选手类型' }, // 0:单打,user;1:双打,teamApply
-  player_one: { type: String, required: true, zh: '选手一', refPath: 'player_type' }, //
+  player_one: { type: String, required: true, zh: '选手一' }, // , refPath: 'player_type'
   player_one_score: { type: String, required: false, zh: '选手一比分' }, //
-  player_two: { type: String, required: true, zh: '选手二', refPath: 'player_type' }, //
+  player_two: { type: String, required: true, zh: '选手二' }, // , refPath: 'player_type'
   player_two_score: { type: String, required: false, zh: '选手二比分' }, //
   is_change: { type: String, required: false, default: '0', zh: '是否交换' }, // 0:未交换,1:已交换
   status: { type: String, required: false, default: '0', zh: '赛程状态' }, // 0:待开始,1:已开始,2:已结束

+ 8 - 8
app/service/matchSmallGroupSchedule.js

@@ -89,7 +89,7 @@ class MatchSmallGroupScheduleService extends CrudService {
     data = JSON.parse(JSON.stringify(data));
     for (const d of data) {
       const { player_type, player_one, player_two, referee_id } = d;
-      if (player_type === 'User') {
+      if (player_type === 'Race.User') {
         const pouid = _.get(player_one, 'user_id');
         const user1 = await this.baseUserModel.findById(pouid);
         d.player_one_name = _.get(user1, 'name');
@@ -98,11 +98,11 @@ class MatchSmallGroupScheduleService extends CrudService {
         const user2 = await this.baseUserModel.findById(ptuid);
         d.player_two_name = _.get(user2, 'name');
         d.player_two = _.get(d, 'player_two._id');
-      } else if (player_type === 'TeamApply') {
-        // d.player_one_name = `${_.get(d, 'player_one.one_member_name')}-${_.get(d, 'player_one.two_member_name')}`;
-        // d.player_one = _.get(d, 'player_one._id');
-        // d.player_two_name = `${_.get(d, 'player_two.one_member_name')}-${_.get(d, 'player_two.two_member_name')}`;
-        // d.player_two = _.get(d, 'player_two._id');
+      } else if (player_type === 'Race.TeamApply') {
+        const p1 = await this.teamApplyModel.findById(player_one);
+        const p2 = await this.teamApplyModel.findById(player_two);
+        d.player_one_name = `${_.get(p1, 'one_member_name')}-${_.get(p1, 'two_member_name')}`;
+        d.player_two_name = `${_.get(p2, 'one_member_name')}-${_.get(p2, 'two_member_name')}`;
       }
 
       const referee = await this.userModel.findById(referee_id).populate({
@@ -154,7 +154,7 @@ class MatchSmallGroupScheduleService extends CrudService {
   }
   async afterFetch(filter, d) {
     const { player_type, player_one, player_two, referee_id } = d;
-    if (player_type === 'User') {
+    if (player_type === 'Race.User') {
       const pouid = _.get(player_one, 'user_id');
       const user1 = await this.baseUserModel.findById(pouid);
       d.player_one_name = _.get(user1, 'name');
@@ -163,7 +163,7 @@ class MatchSmallGroupScheduleService extends CrudService {
       const user2 = await this.baseUserModel.findById(ptuid);
       d.player_two_name = _.get(user2, 'name');
       d.player_two = _.get(d, 'player_two._id');
-    } else if (player_type === 'TeamApply') {
+    } else if (player_type === 'Race.TeamApply') {
       d.player_one_name = `${_.get(d, 'player_one.one_member_name')}-${_.get(d, 'player_one.two_member_name')}`;
       d.player_one = _.get(d, 'player_one._id');
       d.player_two_name = `${_.get(d, 'player_two.one_member_name')}-${_.get(d, 'player_two.two_member_name')}`;

+ 12 - 12
app/service/matchTeamGroup.js

@@ -32,7 +32,7 @@ class MatchTeamGroupService extends CrudService {
     // 2.查找该项目下已经分完组的成员, 如果是针对某组的修改,则不查该组
     const teamGroups = await this.model.find({ project_id, _id: { $ne: team_id } }, { person: 1 });
     // 已经有分组的成员id集合
-    const personList = _.flattenDeep(teamGroups.map((i) => i.person));
+    const personList = _.flattenDeep(teamGroups.map(i => i.person));
     if (person_type === 'Race.TeamApply') {
       allPerson = await this.teamApplyModel.find({ project_id, status: '1', _id: { $nin: personList } });
     } else {
@@ -47,7 +47,7 @@ class MatchTeamGroupService extends CrudService {
         },
       });
       allPerson = JSON.parse(JSON.stringify(allPerson));
-      allPerson = allPerson.map((i) => {
+      allPerson = allPerson.map(i => {
         i.user_name = _.get(i, 'user_id.user_id.name');
         i.user_id = _.get(i, 'user_id._id');
         return i;
@@ -56,7 +56,7 @@ class MatchTeamGroupService extends CrudService {
 
     // 过滤掉 allPerson 中 在personList中的数据
     if (person_type === 'Race.TeamApply') {
-      allPerson = allPerson.filter((f) => !personList.includes(f._id));
+      allPerson = allPerson.filter(f => !personList.includes(f._id));
       return allPerson;
     }
     return allPerson;
@@ -69,7 +69,7 @@ class MatchTeamGroupService extends CrudService {
     const canOpera = await this.canOpera(match_id);
     if (!canOpera) throw new BusinessError(ErrorCode.SERVICE_FAULT, '当前赛事不处于可更改赛事相关信息状态');
     const project_id = _.get(_.head(data), 'project_id');
-    const belongOneProject = data.every((e) => e.project_id === project_id);
+    const belongOneProject = data.every(e => e.project_id === project_id);
     if (!belongOneProject) throw new BusinessError(ErrorCode.DATA_INVALID, '自动创建的小组并不全都属于同一个比赛项目,无法创建小组');
     // 先删除该比赛项目的所有小组
     await this.model.deleteMany({ project_id });
@@ -160,7 +160,7 @@ class MatchTeamGroupService extends CrudService {
     const { project_name } = filter;
     if (project_name) {
       const projectList = await this.matchProjectModel.find({ name: new RegExp(project_name) }, { _id: 1 });
-      const project_id = projectList.map((i) => i._id);
+      const project_id = projectList.map(i => i._id);
       filter.project_id = project_id;
       delete filter.project_name;
     }
@@ -200,8 +200,8 @@ class MatchTeamGroupService extends CrudService {
       if (person_type === 'Race.User') {
         // 单人
         const users = await this.userModel.find({ _id: person }).populate({ path: 'user_id', model: this.baseUserModel, select: 'name' });
-        const parr = person.map((i) => {
-          const r = users.find((f) => ObjectId(f._id).equals(i));
+        const parr = person.map(i => {
+          const r = users.find(f => ObjectId(f._id).equals(i));
           if (r) return { id: r._id, name: _.get(r, 'user_id.name') };
           return i;
         });
@@ -211,7 +211,7 @@ class MatchTeamGroupService extends CrudService {
         const teamApplys = await this.teamApplyModel.find({ _id: person });
         const parr = [];
         for (const p of person) {
-          const r = teamApplys.find((f) => ObjectId(f._id).equals(p));
+          const r = teamApplys.find(f => ObjectId(f._id).equals(p));
           if (r) {
             const { one_member_name, two_member_name } = r;
             parr.push({ id: p, name: `${one_member_name}-${two_member_name}` });
@@ -228,8 +228,8 @@ class MatchTeamGroupService extends CrudService {
     if (person_type === 'Race.User') {
       // 单人
       const users = await this.userModel.find({ _id: person }).populate({ path: 'user_id', model: this.baseUserModel, select: 'name' });
-      const parr = person.map((i) => {
-        const r = users.find((f) => ObjectId(f._id).equals(i));
+      const parr = person.map(i => {
+        const r = users.find(f => ObjectId(f._id).equals(i));
         if (r) return { id: r._id, name: _.get(r, 'user_id.name') };
         return i;
       });
@@ -239,7 +239,7 @@ class MatchTeamGroupService extends CrudService {
       const teamApplys = await this.teamApplyModel.find({ _id: person });
       const parr = [];
       for (const p of person) {
-        const r = teamApplys.find((f) => ObjectId(f._id).equals(p));
+        const r = teamApplys.find(f => ObjectId(f._id).equals(p));
         if (r) {
           const { one_member_name, two_member_name } = r;
           parr.push({ id: p, name: `${one_member_name}-${two_member_name}` });
@@ -258,7 +258,7 @@ class MatchTeamGroupService extends CrudService {
    * @return {Boolean} 是否可以操作
    */
   async canOpera(match_id) {
-    const num = await this.matchModel.count({ _id: match_id, status: ['1', '2'] });
+    const num = await this.matchModel.count({ _id: match_id, status: [ '1', '2' ] });
     return num > 0;
   }
 }