1234567891011121314151617181920212223242526272829303132333435363738 |
- '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;
- }
- // 教练成为本校的裁判
- 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');
- const parent_id = 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: school_id };
- const res = await this.httpUtil.cpost(`${this.baseUrl}/user/bindJudge`, obj);
- return res;
- }
- }
- module.exports = RaceService;
|