lrf 2 năm trước cách đây
mục cha
commit
aeb6b2ae0b
1 tập tin đã thay đổi với 16 bổ sung17 xóa
  1. 16 17
      app/service/matchTeamGroup.js

+ 16 - 17
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 });
@@ -156,12 +156,11 @@ class MatchTeamGroupService extends CrudService {
     return { filter, update };
   }
 
-
   async beforeQuery(filter) {
     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;
     }
@@ -198,21 +197,21 @@ class MatchTeamGroupService extends CrudService {
     data = JSON.parse(JSON.stringify(data));
     for (const d of data) {
       const { person, person_type } = d;
-      if (person_type === 'User') {
+      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;
         });
         d.person = parr;
-      } else if (person_type === 'TeamApply') {
+      } else if (person_type === 'Race.TeamApply') {
         // 组队
         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}` });
@@ -226,21 +225,21 @@ class MatchTeamGroupService extends CrudService {
   }
   async afterFetch(filter, d) {
     const { person = [], person_type } = d;
-    if (person_type === 'User') {
+    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;
       });
       d.person = parr;
-    } else if (person_type === 'TeamApply') {
+    } else if (person_type === 'Race.TeamApply') {
       // 组队
       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}` });
@@ -259,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;
   }
 }