Skip to content

Commit

Permalink
Merge pull request #217 from boostcampwm2023/hotfix/game-start
Browse files Browse the repository at this point in the history
  • Loading branch information
Daehyun Kim authored Dec 12, 2023
2 parents 35007c6 + 2c5b78c commit 870c2ec
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
13 changes: 9 additions & 4 deletions server/src/problem/problem.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,14 @@ export class ProblemService {
}

async getProblemsByBojProblemIds(bojProblemIds: number[]) {
return await this.problemRepository
.createQueryBuilder('problem')
.where('problem.bojProblemId IN (:...bojProblemIds)', { bojProblemIds })
.getMany();
const problemEntities: Problem[] = [];
for (const bojProblemId of bojProblemIds) {
const problem = await this.getProblemByBojProblemId(bojProblemId);
if (problem == null) {
throw new Error(`bojProblemId ${bojProblemId} not found`);
}
problemEntities.push(problem);
}
return problemEntities;
}
}
5 changes: 3 additions & 2 deletions server/src/socket/socket.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -163,8 +163,9 @@ export class SocketService {
if (problems == null) throw new WsException('problems is null');
if (duration == null) throw new WsException('duration is null');
const bojProblemIds = problems.map((problem) => problem.bojProblemId);
room.problems =
this.problemService.getProblemsByBojProblemIds(bojProblemIds);
const problemEntities =
await this.problemService.getProblemsByBojProblemIds(bojProblemIds);
room.problems = Promise.resolve(problemEntities);

room.isStarted = true;
room.endAt = new Date(Date.now() + duration * 60 * 1000);
Expand Down

0 comments on commit 870c2ec

Please sign in to comment.