|
@@ -1,50 +0,0 @@
|
|
|
-'use strict';
|
|
|
-const { CrudService } = require('naf-framework-mongoose-free/lib/service');
|
|
|
-const { BusinessError, ErrorCode } = require('naf-core').Error;
|
|
|
-const _ = require('lodash');
|
|
|
-const assert = require('assert');
|
|
|
-
|
|
|
-// 与race模块相关联的处理
|
|
|
-class RaceService extends CrudService {
|
|
|
- constructor(ctx) {
|
|
|
- super(ctx, 'race');
|
|
|
- this.coachModel = this.ctx.model.User.Coach;
|
|
|
- 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 }) {
|
|
|
- const coach = await this.coachModel.findById(coach_id).populate('user_id');
|
|
|
- if (!coach) throw new BusinessError(ErrorCode.DATA_NOT_EXIST, '未找到教练信息');
|
|
|
- const user_id = _.get(coach, 'user_id._id');
|
|
|
- const openid = _.get(coach, 'user_id.openid');
|
|
|
- // 查找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;
|
|
|
- }
|
|
|
- // 用户绑定为教练
|
|
|
- async userToBeJudge({ user_id, school_id }) {
|
|
|
- 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: 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;
|