lrf 2 years ago
parent
commit
b42089af9d

+ 1 - 1
app/model/race/matchProject.js

@@ -5,7 +5,7 @@ const metaPlugin = require('naf-framework-mongoose-free/lib/model/meta-plugin');
 // 组别项目
 const match_project = {
   match_id: { type: String, required: true, zh: '赛事id', ref: 'Race.Match', getProp: [ 'name' ] }, // 比赛信息中的比赛名称
-  group_id: { type: String, required: true, zh: '赛事分组id', ref: 'MatchGroup', getProp: [ 'name' ] }, // 赛事分组中的组名称
+  group_id: { type: String, required: true, zh: '赛事分组id', ref: 'Race.MatchGroup', getProp: [ 'name' ] }, // 赛事分组中的组名称
   type: { type: String, required: true, zh: '项目类别' }, // 字典表中的标签
   name: { type: String, required: true, zh: '名称' }, //
   age: { type: String, required: false, zh: '年龄限制' }, // 12-16 / null(不限)

+ 24 - 30
app/service/matchSmallGroupSchedule.js

@@ -85,32 +85,6 @@ class MatchSmallGroupScheduleService extends CrudService {
     return filter;
   }
 
-  turnFilter(filter) {
-    const str = /^%\S*%$/;
-    // $是mongodb固定条件,不用处理;大多为手写特殊处理过的条件
-    let keys = Object.keys(filter).filter(f => !f.includes('$'));
-    for (const key of keys) {
-      const res = key.match(str);
-      if (res) {
-        const newKey = key.slice(1, key.length - 1);
-        if (!ObjectId.isValid(filter[key])) filter[newKey] = new RegExp(filter[key]);
-        delete filter[key];
-      }
-    }
-    // 再次过滤数据,将数组的数据都变成{$in:value},因为查询变成了聚合查询
-    // $是mongodb固定条件,不用处理;大多为手写特殊处理过的条件
-    keys = Object.keys(filter).filter(f => !f.includes('$'));
-    for (const key of keys) {
-      if (_.isArray(filter[key])) {
-        filter[key] = { $in: filter[key] };
-      } else if (filter[key] === 'true' || filter[key] === 'false') {
-        // 布尔类型的值检查,如果是布尔类型,则将字符串转为布尔
-        filter[key] = filter[key] === 'true';
-      }
-    }
-    return filter;
-  }
-
   async afterQuery(filter, data) {
     data = JSON.parse(JSON.stringify(data));
     for (const d of data) {
@@ -125,10 +99,10 @@ class MatchSmallGroupScheduleService extends CrudService {
         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');
+        // 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');
       }
 
       const referee = await this.userModel.findById(referee_id).populate({
@@ -203,6 +177,26 @@ class MatchSmallGroupScheduleService extends CrudService {
 
     return d;
   }
+
+  // 针对每个表进行检查
+  resetPopulate(schema) {
+    const arr = [];
+    for (const key in schema) {
+      const e = schema[key];
+      const { ref, refPath } = e;
+      if (!ref && !refPath) continue;
+      const refValue = ref || refPath;
+      const obj = { path: key };
+      const modelPath = this.formatModelPath(refValue);
+      const model = this.getModel(modelPath);
+      obj.model = model;
+      const msch = this.getSchema(modelPath);
+      const popu = this.resetPopulate(msch);
+      if (popu.length > 0) obj.populate = popu;
+      arr.push(obj);
+    }
+    return arr;
+  }
 }
 
 module.exports = MatchSmallGroupScheduleService;

+ 2 - 2
app/service/matchTeamGroup.js

@@ -33,7 +33,7 @@ class MatchTeamGroupService extends CrudService {
     const teamGroups = await this.model.find({ project_id, _id: { $ne: team_id } }, { person: 1 });
     // 已经有分组的成员id集合
     const personList = _.flattenDeep(teamGroups.map(i => i.person));
-    if (person_type === 'TeamApply') {
+    if (person_type === 'Race.TeamApply') {
       allPerson = await this.teamApplyModel.find({ project_id, status: '1', _id: { $nin: personList } });
     } else {
       allPerson = await this.matchSignModel.find({ project_id, pay_status: '1', user_id: { $nin: personList } }).populate({
@@ -55,7 +55,7 @@ class MatchTeamGroupService extends CrudService {
     }
 
     // 过滤掉 allPerson 中 在personList中的数据
-    if (person_type === 'TeamApply') {
+    if (person_type === 'Race.TeamApply') {
       allPerson = allPerson.filter(f => !personList.includes(f._id));
       return allPerson;
     }