lrf 2 years ago
parent
commit
3174ab8868
3 changed files with 22 additions and 20 deletions
  1. 4 4
      app/model/race/matchTeamGroup.js
  2. 8 1
      app/service/match.js
  3. 10 15
      app/service/matchTeamGroup.js

+ 4 - 4
app/model/race/matchTeamGroup.js

@@ -4,12 +4,12 @@ const metaPlugin = require('naf-framework-mongoose-free/lib/model/meta-plugin');
 
 // 小组赛组设置
 const match_team_group = {
-  match_id: { type: String, required: true, zh: '赛事id', ref: 'Match', getProp: [ 'name' ] }, // 比赛信息中的名称
-  group_id: { type: String, required: true, zh: '组别id', ref: 'MatchGroup', getProp: [ 'name' ] }, // 赛事组别中的名称
-  project_id: { type: String, required: true, zh: '项目id', ref: 'MatchProject', getProp: [ 'name' ] }, // 组内项目中的名称
+  match_id: { type: String, required: true, zh: '赛事id', ref: 'Match', getProp: ['name'] }, // 比赛信息中的名称
+  group_id: { type: String, required: true, zh: '组别id', ref: 'MatchGroup', getProp: ['name'] }, // 赛事组别中的名称
+  project_id: { type: String, required: true, zh: '项目id', ref: 'MatchProject', getProp: ['name'] }, // 组内项目中的名称
   name: { type: String, required: true, zh: '分组名称' }, //
   person_type: { type: String, required: false, zh: '人员类型' }, // 单打:user;双打:teamApply
-  person: { type: Array, required: false, zh: '组内人员', refPath: 'person_type' }, //
+  person: { type: Array, required: false, zh: '组内人员' }, // refPath: 'person_type'
   remark: { type: String, required: false, zh: '备注' }, //
   rise: { type: String, required: true, zh: '取前几' }, //
 };

+ 8 - 1
app/service/match.js

@@ -4,12 +4,19 @@ const { BusinessError, ErrorCode } = require('naf-core').Error;
 const _ = require('lodash');
 const assert = require('assert');
 
-// 
+//
 class MatchService extends CrudService {
   constructor(ctx) {
     super(ctx, 'match');
     this.model = this.ctx.model.Race.Match;
   }
+  /**
+   * 
+   * @param {*} param0 
+   */
+  async getAll({ id }) {
+
+  }
 }
 
 module.exports = MatchService;

+ 10 - 15
app/service/matchTeamGroup.js

@@ -14,6 +14,7 @@ class MatchTeamGroupService extends CrudService {
     this.teamApplyModel = this.ctx.model.Race.TeamApply;
     this.matchSignModel = this.ctx.model.Race.MatchSign;
     this.baseUserModel = this.ctx.model.Base.User;
+    this.userModel = this.ctx.model.Race.User;
   }
   /**
    * 根据项目和选手类型查询可选择的分组人员
@@ -48,29 +49,23 @@ class MatchTeamGroupService extends CrudService {
     // 找人的信息
     allPerson = allPerson.filter(f => !personList.includes(f.user_id));
     const users = [];
+    const conn = this.app.mongooseDB.get('base');
+    const schema = _.get(this.ctx.model, 'Base.User.schema');
+    const m = conn.model('User', schema);
     for (const i of allPerson) {
       const { user_id } = i;
-      const r = await this.ctx.service.user.fetch({ id: user_id });
-      users.push(r);
+      const user = await this.userModel.findById(user_id).populate({
+        path: 'user_id',
+        select: 'name',
+        model: m,
+      });
+      users.push({ ...JSON.parse(JSON.stringify(i)), user_name: _.get(user, 'user_id.name') });
     }
     return users;
 
 
   }
 
-
-  // 将选手的信息换出来
-  async afterQuery(filter, data) {
-    for (const i of data) {
-      const { person_type } = i;
-      if (person_type === 'User') {
-        const users = await this.baseUserModel.find({ _id: i.person });
-        i.person = users;
-      }
-    }
-    return data;
-  }
-
   async saveAll(data) {
     for (const i of data) {
       const { _id } = i;