.
This commit is contained in:
1 parent
673ee3d80a
commit
bd3cd4fa5f
9 files changed
+332
-3
No files matched your search
@@ -43,6 +43,11 @@ interface JoinMatchParams {
|
||||
riotPuuid?: string;
|
||||
}
|
||||
|
||||
interface CancelMatchJoinParams {
|
||||
matchId: mongoose.Types.ObjectId;
|
||||
userId: mongoose.Types.ObjectId;
|
||||
}
|
||||
|
||||
@Injectable()
|
||||
export class MatchService {
|
||||
constructor(
|
||||
@@ -209,6 +214,38 @@ export class MatchService {
|
||||
return match;
|
||||
}
|
||||
|
||||
public async cancelJoin(
|
||||
params: CancelMatchJoinParams,
|
||||
): Promise<MatchDocument> {
|
||||
const MatchModel = await this.connectionService.getModel('match');
|
||||
const UserModel = await this.connectionService.getModel('user');
|
||||
|
||||
const user = await UserModel.findById(params.userId);
|
||||
if (!user) throw new NotFoundException('User not found.');
|
||||
|
||||
const match = await MatchModel.findById(params.matchId);
|
||||
if (!match) throw new NotFoundException('Match not found.');
|
||||
if (!match.communityId.equals(user.communityId)) {
|
||||
throw new BadRequestException(
|
||||
'User and match belong to different communities.',
|
||||
);
|
||||
}
|
||||
if (match.status !== 'recruiting') {
|
||||
throw new BadRequestException('Match is not recruiting.');
|
||||
}
|
||||
|
||||
const participantIndex = match.participants.findIndex((participant) =>
|
||||
participant.userId.equals(user._id),
|
||||
);
|
||||
if (participantIndex === -1) {
|
||||
throw new BadRequestException('User has not joined this match.');
|
||||
}
|
||||
|
||||
match.participants.splice(participantIndex, 1);
|
||||
await match.save();
|
||||
return match;
|
||||
}
|
||||
|
||||
private selectParticipantTier(tiers: TierInfo[]): TierInfo | undefined {
|
||||
const tier =
|
||||
tiers.find((entry) => entry.queueType === 'RANKED_SOLO_5x5') ?? tiers[0];
|
||||
|
||||
Reference in new issue
Block a user