|
@@ -12,6 +12,7 @@ class RaceService extends CrudService {
|
|
|
this.baseUrl = _.get(this.app.config, 'httpPrefix.race');
|
|
|
this.httpUtil = this.ctx.service.util.httpUtil;
|
|
|
this.userModel = this.ctx.model.User.User;
|
|
|
+ this.schoolModel = this.ctx.model.User.School;
|
|
|
}
|
|
|
// 教练成为本校的裁判
|
|
|
async coachToBeJudge({ coach_id, school_id }) {
|
|
@@ -19,7 +20,8 @@ class RaceService extends CrudService {
|
|
|
if (!coach) throw new BusinessError(ErrorCode.DATA_NOT_EXIST, '未找到教练信息');
|
|
|
const user_id = _.get(coach, 'user_id._id');
|
|
|
const openid = _.get(coach, 'user_id.openid');
|
|
|
- const parent_id = school_id;
|
|
|
+ // 查找parent_id
|
|
|
+ const parent_id = await this.getPatentId(school_id);
|
|
|
const obj = { user_id, type: '2', openid, parent_id };
|
|
|
const res = await this.httpUtil.cpost(`${this.baseUrl}/user/bindJudge`, obj);
|
|
|
return res;
|
|
@@ -29,10 +31,20 @@ class RaceService extends CrudService {
|
|
|
const user = await this.userModel.findById(user_id);
|
|
|
if (!user) throw new BusinessError(ErrorCode.DATA_NOT_EXIST, '未找到用户信息');
|
|
|
const { openid } = user;
|
|
|
- const obj = { user_id, type: '2', openid, parent_id: school_id };
|
|
|
+ const obj = { user_id, type: '2', openid, parent_id: await this.getPatentId(school_id) };
|
|
|
const res = await this.httpUtil.cpost(`${this.baseUrl}/user/bindJudge`, obj);
|
|
|
return res;
|
|
|
}
|
|
|
+ // 根据学校id,查询比赛项目中的用户的id
|
|
|
+ async getPatentId(school_id) {
|
|
|
+ const data = await this.schoolModel.findById(school_id).populate('user_id');
|
|
|
+ if (!data) throw new BusinessError(ErrorCode.DATA_NOT_EXIST, '未找到学校信息');
|
|
|
+ const user_id = _.get(data, 'user_id._id');
|
|
|
+ if (!user_id) throw new BusinessError(ErrorCode.DATA_NOT_EXIST, '未找到学校用户信息');
|
|
|
+ const res = await this.httpUtil.cget(`${this.baseUrl}/user?user_id=${user_id}`);
|
|
|
+ if (!res) throw new BusinessError(ErrorCode.DATA_NOT_EXIST, '未找到比赛模块用户信息');
|
|
|
+ return _.get(res, '_id');
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
module.exports = RaceService;
|