fix: stabilize competition results flow
This commit is contained in:
1 parent
3bd3120eb1
commit
a88562b208
20 files changed
+411
-65
No files matched your search
@@ -22,6 +22,17 @@ export interface CompetitionScope {
|
||||
matchId: mongoose.Types.ObjectId;
|
||||
}
|
||||
|
||||
/**
|
||||
* A team view is addressed either by the caller's membership (signed-in) or by
|
||||
* an explicit team id. The explicit form exists so that the team progress page
|
||||
* stays usable while community members have not all signed in yet.
|
||||
*/
|
||||
export type TeamViewScope = CompetitionScope &
|
||||
(
|
||||
| { userId: mongoose.Types.ObjectId; teamId?: undefined }
|
||||
| { teamId: mongoose.Types.ObjectId; userId?: undefined }
|
||||
);
|
||||
|
||||
interface CompetitionProjectionSource {
|
||||
series?: Array<Record<string, unknown>>;
|
||||
gameSlots?: Array<Record<string, unknown>>;
|
||||
@@ -68,15 +79,21 @@ export class CompetitionQueryService {
|
||||
}
|
||||
|
||||
public async getTeamView(
|
||||
scope: CompetitionScope & { userId: mongoose.Types.ObjectId },
|
||||
scope: TeamViewScope,
|
||||
): Promise<TeamCompetitionViewResponse> {
|
||||
const competition = (await this.getCompetition(scope)) as Competition & {
|
||||
_id: PersistenceId;
|
||||
};
|
||||
const team = competition.teams.find(({ members }) =>
|
||||
members.some(({ userId }) => sameId(userId, scope.userId)),
|
||||
);
|
||||
const requestedTeamId = scope.teamId;
|
||||
const team = requestedTeamId
|
||||
? competition.teams.find(({ teamId }) => sameId(teamId, requestedTeamId))
|
||||
: competition.teams.find(({ members }) =>
|
||||
members.some(({ userId }) => sameId(userId, scope.userId)),
|
||||
);
|
||||
if (!team) {
|
||||
if (requestedTeamId) {
|
||||
throw new NotFoundException('Competition team not found.');
|
||||
}
|
||||
throw new ForbiddenException(
|
||||
'Only a Competition team member may access the team view.',
|
||||
);
|
||||
|
||||
Reference in new issue
Block a user