fix: close competition cutover integrity gaps
This commit is contained in:
1 parent
7ea2002975
commit
683d602d63
57 files changed
+4805
-1582
No files matched your search
@@ -1,3 +1,7 @@
|
||||
import type {
|
||||
MatchDetailResponse,
|
||||
MatchListResponse,
|
||||
} from '@lolympus/contracts';
|
||||
import {
|
||||
BadRequestException,
|
||||
Body,
|
||||
@@ -23,7 +27,6 @@ import {
|
||||
AddParticipantDto,
|
||||
CreateMatchDto,
|
||||
JoinMatchDto,
|
||||
SwapDoubleEliminationSeedsDto,
|
||||
UpdateMatchDto,
|
||||
UpdateParticipantDto,
|
||||
} from './dto/create-match.dto';
|
||||
@@ -41,9 +44,9 @@ export class MatchController {
|
||||
@Param('communityId', ParseObjectIdPipe)
|
||||
communityId: mongoose.Types.ObjectId,
|
||||
@Body() body: CreateMatchDto,
|
||||
) {
|
||||
): Promise<MatchDetailResponse> {
|
||||
this.assertSameCommunity(currentUser, communityId);
|
||||
return this.matchService.create({
|
||||
const match = await this.matchService.create({
|
||||
communityId,
|
||||
hostUserId: currentUser._id,
|
||||
data: {
|
||||
@@ -62,6 +65,7 @@ export class MatchController {
|
||||
schedule: body.schedule ?? [],
|
||||
},
|
||||
});
|
||||
return this.matchService.serialize(match, { joined: false });
|
||||
}
|
||||
|
||||
// 공개 — 커뮤니티 내 매치 리스트. 로그인 시 본인 참여 여부를 함께 반환.
|
||||
@@ -78,7 +82,7 @@ export class MatchController {
|
||||
@Query('scheduledFrom') scheduledFrom?: string,
|
||||
@Query('scheduledTo') scheduledTo?: string,
|
||||
@Query('sort') sort?: 'asc' | 'desc',
|
||||
) {
|
||||
): Promise<MatchListResponse> {
|
||||
const result = await this.matchService.listPage({
|
||||
communityId,
|
||||
status,
|
||||
@@ -108,10 +112,20 @@ export class MatchController {
|
||||
@Get(':matchId')
|
||||
@AllowPublicAccess()
|
||||
public async getMatch(
|
||||
@CurrentUser() currentUser: UserDocument | undefined,
|
||||
@Param('communityId', ParseObjectIdPipe)
|
||||
communityId: mongoose.Types.ObjectId,
|
||||
@Param('matchId', ParseObjectIdPipe) matchId: mongoose.Types.ObjectId,
|
||||
) {
|
||||
const match = await this.matchService.getById(matchId);
|
||||
return this.matchService.serialize(match);
|
||||
): Promise<MatchDetailResponse> {
|
||||
const match = await this.matchService.getById(matchId, communityId);
|
||||
return this.matchService.serialize(match, {
|
||||
joined: Boolean(
|
||||
currentUser &&
|
||||
match.participants.some((participant) =>
|
||||
participant.userId.equals(currentUser._id),
|
||||
),
|
||||
),
|
||||
});
|
||||
}
|
||||
|
||||
@Patch(':matchId')
|
||||
@@ -123,48 +137,18 @@ export class MatchController {
|
||||
communityId: mongoose.Types.ObjectId,
|
||||
@Param('matchId', ParseObjectIdPipe) matchId: mongoose.Types.ObjectId,
|
||||
@Body() body: UpdateMatchDto,
|
||||
) {
|
||||
): Promise<MatchDetailResponse> {
|
||||
this.assertSameCommunity(currentUser, communityId);
|
||||
return this.matchService.update({ matchId, communityId, patch: body });
|
||||
}
|
||||
|
||||
@Post(':matchId/double-elimination/seeds/reshuffle')
|
||||
@Roles('admin', 'owner')
|
||||
@UseGuards(RolesGuard)
|
||||
public async reshuffleDoubleEliminationSeeds(
|
||||
@CurrentUser() currentUser: UserDocument,
|
||||
@Param('communityId', ParseObjectIdPipe)
|
||||
communityId: mongoose.Types.ObjectId,
|
||||
@Param('matchId', ParseObjectIdPipe) matchId: mongoose.Types.ObjectId,
|
||||
) {
|
||||
this.assertSameCommunity(currentUser, communityId);
|
||||
const match = await this.matchService.reshuffleDoubleEliminationSeeds({
|
||||
const match = await this.matchService.update({
|
||||
matchId,
|
||||
communityId,
|
||||
actorUserId: currentUser._id,
|
||||
patch: body,
|
||||
});
|
||||
return this.matchService.serialize(match);
|
||||
}
|
||||
|
||||
@Post(':matchId/double-elimination/seeds/swap')
|
||||
@Roles('admin', 'owner')
|
||||
@UseGuards(RolesGuard)
|
||||
public async swapDoubleEliminationSeeds(
|
||||
@CurrentUser() currentUser: UserDocument,
|
||||
@Param('communityId', ParseObjectIdPipe)
|
||||
communityId: mongoose.Types.ObjectId,
|
||||
@Param('matchId', ParseObjectIdPipe) matchId: mongoose.Types.ObjectId,
|
||||
@Body() body: SwapDoubleEliminationSeedsDto,
|
||||
) {
|
||||
this.assertSameCommunity(currentUser, communityId);
|
||||
const match = await this.matchService.swapDoubleEliminationSeeds({
|
||||
matchId,
|
||||
communityId,
|
||||
actorUserId: currentUser._id,
|
||||
leftSeedNumber: body.leftSeedNumber,
|
||||
rightSeedNumber: body.rightSeedNumber,
|
||||
return this.matchService.serialize(match, {
|
||||
joined: match.participants.some((participant) =>
|
||||
participant.userId.equals(currentUser._id),
|
||||
),
|
||||
});
|
||||
return this.matchService.serialize(match);
|
||||
}
|
||||
|
||||
@Delete(':matchId')
|
||||
@@ -181,20 +165,25 @@ export class MatchController {
|
||||
await this.matchService.remove({ matchId, communityId });
|
||||
}
|
||||
|
||||
// 공개 — 참여 (로그인된 유저는 자기 자신, 비로그인은 body.userId 사용).
|
||||
// 커뮤니티 멤버 본인 참여. 다른 유저 추가는 관리자 전용 경로를 사용한다.
|
||||
@Post(':matchId/participants')
|
||||
@AllowPublicAccess()
|
||||
@Roles('owner', 'admin', 'member')
|
||||
@UseGuards(RolesGuard)
|
||||
public async joinMatch(
|
||||
@CurrentUser() currentUser: UserDocument | undefined,
|
||||
@CurrentUser() currentUser: UserDocument,
|
||||
@Param('communityId', ParseObjectIdPipe)
|
||||
communityId: mongoose.Types.ObjectId,
|
||||
@Param('matchId', ParseObjectIdPipe) matchId: mongoose.Types.ObjectId,
|
||||
@Body() body: JoinMatchDto,
|
||||
) {
|
||||
const userId = this.resolveJoinerUserId(currentUser, body.userId);
|
||||
return this.matchService.join({
|
||||
): Promise<MatchDetailResponse> {
|
||||
this.assertSameCommunity(currentUser, communityId);
|
||||
const match = await this.matchService.join({
|
||||
matchId,
|
||||
userId,
|
||||
communityId,
|
||||
userId: currentUser._id,
|
||||
preferredPositions: body.preferredPositions,
|
||||
});
|
||||
return this.matchService.serialize(match, { joined: true });
|
||||
}
|
||||
|
||||
// 관리자 전용 — 커뮤니티 유저를 모집중 매치에 직접 추가한다.
|
||||
@@ -208,15 +197,20 @@ export class MatchController {
|
||||
@Param('matchId', ParseObjectIdPipe) matchId: mongoose.Types.ObjectId,
|
||||
@Param('userId', ParseObjectIdPipe) userId: mongoose.Types.ObjectId,
|
||||
@Body() body: AddParticipantDto | undefined,
|
||||
) {
|
||||
): Promise<MatchDetailResponse> {
|
||||
this.assertSameCommunity(currentUser, communityId);
|
||||
const match = await this.matchService.join({
|
||||
matchId,
|
||||
communityId,
|
||||
userId,
|
||||
preferredPositions: body?.preferredPositions,
|
||||
riotPuuid: body?.riotPuuid,
|
||||
});
|
||||
return this.matchService.serialize(match);
|
||||
return this.matchService.serialize(match, {
|
||||
joined: match.participants.some((participant) =>
|
||||
participant.userId.equals(currentUser._id),
|
||||
),
|
||||
});
|
||||
}
|
||||
|
||||
// 관리자 전용 — 참가자 주/부 포지션 변경.
|
||||
@@ -230,7 +224,7 @@ export class MatchController {
|
||||
@Param('matchId', ParseObjectIdPipe) matchId: mongoose.Types.ObjectId,
|
||||
@Param('userId', ParseObjectIdPipe) userId: mongoose.Types.ObjectId,
|
||||
@Body() body: UpdateParticipantDto,
|
||||
) {
|
||||
): Promise<MatchDetailResponse> {
|
||||
this.assertSameCommunity(currentUser, communityId);
|
||||
const match = await this.matchService.updateParticipantPositions({
|
||||
matchId,
|
||||
@@ -239,7 +233,11 @@ export class MatchController {
|
||||
mainPosition: body.mainPosition,
|
||||
subPosition: body.subPosition,
|
||||
});
|
||||
return this.matchService.serialize(match);
|
||||
return this.matchService.serialize(match, {
|
||||
joined: match.participants.some((participant) =>
|
||||
participant.userId.equals(currentUser._id),
|
||||
),
|
||||
});
|
||||
}
|
||||
|
||||
// 관리자 전용 — 참가자 강제 제외.
|
||||
@@ -262,19 +260,6 @@ export class MatchController {
|
||||
});
|
||||
}
|
||||
|
||||
private resolveJoinerUserId(
|
||||
currentUser: UserDocument | undefined,
|
||||
bodyUserId?: string,
|
||||
): mongoose.Types.ObjectId {
|
||||
if (currentUser) return currentUser._id;
|
||||
if (!bodyUserId || !mongoose.isValidObjectId(bodyUserId)) {
|
||||
throw new BadRequestException(
|
||||
'userId is required when not authenticated.',
|
||||
);
|
||||
}
|
||||
return new mongoose.Types.ObjectId(bodyUserId);
|
||||
}
|
||||
|
||||
private assertSameCommunity(
|
||||
user: UserDocument,
|
||||
communityId: mongoose.Types.ObjectId,
|
||||
|
||||
Reference in new issue
Block a user