race.js 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. 'use strict';
  2. const { CrudService } = require('naf-framework-mongoose-free/lib/service');
  3. const { BusinessError, ErrorCode } = require('naf-core').Error;
  4. const _ = require('lodash');
  5. const assert = require('assert');
  6. // 与race模块相关联的处理
  7. class RaceService extends CrudService {
  8. constructor(ctx) {
  9. super(ctx, 'race');
  10. this.coachModel = this.ctx.model.User.Coach;
  11. this.baseUrl = _.get(this.app.config, 'httpPrefix.race');
  12. this.httpUtil = this.ctx.service.util.httpUtil;
  13. this.userModel = this.ctx.model.User.User;
  14. }
  15. // 教练成为本校的裁判
  16. async coachToBeJudge({ coach_id, school_id }) {
  17. const coach = await this.coachModel.findById(coach_id).populate('user_id');
  18. if (!coach) throw new BusinessError(ErrorCode.DATA_NOT_EXIST, '未找到教练信息');
  19. const user_id = _.get(coach, 'user_id._id');
  20. const openid = _.get(coach, 'user_id.openid');
  21. const parent_id = school_id;
  22. const obj = { user_id, type: '2', openid, parent_id };
  23. const res = await this.httpUtil.cpost(`${this.baseUrl}/user/bindJudge`, obj);
  24. return res;
  25. }
  26. // 用户绑定为教练
  27. async userToBeJudge({ user_id, school_id }) {
  28. const user = await this.userModel.findById(user_id);
  29. if (!user) throw new BusinessError(ErrorCode.DATA_NOT_EXIST, '未找到用户信息');
  30. const { openid } = user;
  31. const obj = { user_id, type: '2', openid, parent_id: school_id };
  32. const res = await this.httpUtil.cpost(`${this.baseUrl}/user/bindJudge`, obj);
  33. return res;
  34. }
  35. }
  36. module.exports = RaceService;