|
@@ -10,6 +10,7 @@ class UserService extends CrudService {
|
|
super(ctx, 'user');
|
|
super(ctx, 'user');
|
|
this.model = this.ctx.model.Race.User;
|
|
this.model = this.ctx.model.Race.User;
|
|
this.baseUserModel = this.ctx.model.Base.User;
|
|
this.baseUserModel = this.ctx.model.Base.User;
|
|
|
|
+ this.baseCoachModel = this.ctx.model.Base.Coach;
|
|
}
|
|
}
|
|
|
|
|
|
async login({ openid }) {
|
|
async login({ openid }) {
|
|
@@ -28,7 +29,6 @@ class UserService extends CrudService {
|
|
return _.head(list);
|
|
return _.head(list);
|
|
}
|
|
}
|
|
|
|
|
|
-
|
|
|
|
async beforeCreate(body) {
|
|
async beforeCreate(body) {
|
|
const { openid, user_id } = body;
|
|
const { openid, user_id } = body;
|
|
const num = await this.model.count({ openid, user_id });
|
|
const num = await this.model.count({ openid, user_id });
|
|
@@ -46,6 +46,25 @@ class UserService extends CrudService {
|
|
else await this.model.create(body);
|
|
else await this.model.create(body);
|
|
return await this.model.findOne({ openid });
|
|
return await this.model.findOne({ openid });
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ // 教练成为裁判
|
|
|
|
+ async coachToBeJudge({ coach_id, parent_id }) {
|
|
|
|
+ const coach = await this.baseCoachModel.findById(coach_id);
|
|
|
|
+ if (!coach) throw new BusinessError(ErrorCode.DATA_NOT_EXIST, '未找到教练信息');
|
|
|
|
+ const { user_id } = coach;
|
|
|
|
+ return await this.userToBeJudge({ user_id, parent_id });
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ // 用户成为裁判
|
|
|
|
+ async userToBeJudge({ user_id, parent_id }) {
|
|
|
|
+ assert(user_id, '缺少裁判用户信息');
|
|
|
|
+ assert(parent_id, '缺少赛事创建方信息');
|
|
|
|
+ const user = await this.baseUserModel.findById(user_id);
|
|
|
|
+ if (!user) throw new BusinessError(ErrorCode.USER_NOT_EXIST, '未找到比赛模块用户信息');
|
|
|
|
+ const { openid } = user;
|
|
|
|
+ const obj = { user_id, parent_id, type: '2', openid };
|
|
|
|
+ return this.bindJudge(obj);
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
|
|
module.exports = UserService;
|
|
module.exports = UserService;
|