|
@@ -12,6 +12,20 @@ class ScheduleService extends CrudService {
|
|
|
super(ctx, 'schedule');
|
|
|
this.model = this.ctx.model.Schedule;
|
|
|
}
|
|
|
+ /**
|
|
|
+ * 通过团队创建人id查询赛程信息
|
|
|
+ * @param {String} id 团队创建人id
|
|
|
+ * @param {Object} options 查询附加参数
|
|
|
+ */
|
|
|
+ async getByTeamCreater({ id }, { skip = 0, limit = 0 } = {}) {
|
|
|
+ // 用 id 查团队表 create_id:id; 获取团队id去查红方和蓝方的赛程信息
|
|
|
+ const team = await this.ctx.model.Team.findOne({ create_id: id }, { _id: 1 });
|
|
|
+ if (!team) throw new BusinessError(ErrorCode.DATA_NOT_EXIST, '未找到该用户的团队信息');
|
|
|
+ const condition = { $or: [{ red_id: team._id }, { blue_id: team._id }] };
|
|
|
+ const data = await this.model.find(condition).skip(parseInt(skip)).limit(parseInt(limit));
|
|
|
+ const total = await this.model.count(condition);
|
|
|
+ return { data, total };
|
|
|
+ }
|
|
|
|
|
|
async checkNeedNext(id) {
|
|
|
const sch = await this.model.findById(id);
|
|
@@ -20,7 +34,7 @@ class ScheduleService extends CrudService {
|
|
|
// 有比分,有位置, 再看看同一轮其他比赛是不是有轮空的.有轮空的就不安排,没有轮空的就直接安排晋级比赛
|
|
|
// 将胜利的队伍的属性取出来,以便下面生成新数据
|
|
|
const winProp = [];
|
|
|
- const propList = [ 'id', 'name', 'logo', 'members' ];
|
|
|
+ const propList = ['id', 'name', 'logo', 'members'];
|
|
|
const winTeam = this.getWinTeam(sch);
|
|
|
for (const p of propList) {
|
|
|
winProp.push({ key: p, value: sch[`${winTeam}_${p}`] });
|
|
@@ -71,7 +85,7 @@ class ScheduleService extends CrudService {
|
|
|
// 修改,一定是将数据放入蓝队中,所以需要判断下蓝队和红队是不是一个队伍,看下id就行
|
|
|
const nmRed_id = _.get(nextMatch, 'red_id');
|
|
|
const winTeamId = _.get(
|
|
|
- winProp.find(f => f.key === 'id'),
|
|
|
+ winProp.find((f) => f.key === 'id'),
|
|
|
'value'
|
|
|
);
|
|
|
if (nmRed_id === winTeamId) return;
|