From 30dfb7ce587850031aa8fe074c63ef8b9d8b2d7a Mon Sep 17 00:00:00 2001 From: dahyeon Date: Fri, 24 Apr 2026 13:40:39 -0700 Subject: [PATCH] . --- apps/api/package.json | 2 + apps/api/src/app.module.ts | 8 + apps/api/src/main.ts | 9 + .../src/modules/auction/auction.controller.ts | 134 +++++++++ .../api/src/modules/auction/auction.module.ts | 10 + .../src/modules/auction/auction.service.ts | 265 ++++++++++++++++++ .../src/modules/auction/dto/auction.dto.ts | 60 ++++ apps/api/src/modules/auth/auth.middleware.ts | 21 ++ apps/api/src/modules/auth/auth.module.ts | 15 + apps/api/src/modules/auth/auth.service.ts | 23 ++ .../modules/auth/current-user.decorator.ts | 9 + apps/api/src/modules/auth/permissions.ts | 35 +++ apps/api/src/modules/auth/roles.decorator.ts | 7 + apps/api/src/modules/auth/roles.guard.ts | 32 +++ .../modules/common/parse-object-id.pipe.ts | 24 ++ .../modules/community/community.controller.ts | 80 ++++++ .../src/modules/community/community.module.ts | 10 + .../modules/community/community.service.ts | 185 ++++++++++++ .../community/dto/create-community.dto.ts | 46 +++ .../community/dto/transfer-ownership.dto.ts | 6 + .../global/database/connection.service.ts | 7 +- .../api/src/modules/global/database/schema.ts | 100 ++++++- .../src/modules/match/dto/create-match.dto.ts | 135 +++++++++ .../api/src/modules/match/match.controller.ts | 163 +++++++++++ apps/api/src/modules/match/match.module.ts | 10 + apps/api/src/modules/match/match.service.ts | 138 +++++++++ pnpm-lock.yaml | 95 +++++-- 27 files changed, 1584 insertions(+), 45 deletions(-) create mode 100644 apps/api/src/modules/auction/auction.controller.ts create mode 100644 apps/api/src/modules/auction/auction.module.ts create mode 100644 apps/api/src/modules/auction/auction.service.ts create mode 100644 apps/api/src/modules/auction/dto/auction.dto.ts create mode 100644 apps/api/src/modules/auth/auth.middleware.ts create mode 100644 apps/api/src/modules/auth/auth.module.ts create mode 100644 apps/api/src/modules/auth/auth.service.ts create mode 100644 apps/api/src/modules/auth/current-user.decorator.ts create mode 100644 apps/api/src/modules/auth/permissions.ts create mode 100644 apps/api/src/modules/auth/roles.decorator.ts create mode 100644 apps/api/src/modules/auth/roles.guard.ts create mode 100644 apps/api/src/modules/common/parse-object-id.pipe.ts create mode 100644 apps/api/src/modules/community/community.controller.ts create mode 100644 apps/api/src/modules/community/community.module.ts create mode 100644 apps/api/src/modules/community/community.service.ts create mode 100644 apps/api/src/modules/community/dto/create-community.dto.ts create mode 100644 apps/api/src/modules/community/dto/transfer-ownership.dto.ts create mode 100644 apps/api/src/modules/match/dto/create-match.dto.ts create mode 100644 apps/api/src/modules/match/match.controller.ts create mode 100644 apps/api/src/modules/match/match.module.ts create mode 100644 apps/api/src/modules/match/match.service.ts diff --git a/apps/api/package.json b/apps/api/package.json index 3b308177..1fd256f6 100644 --- a/apps/api/package.json +++ b/apps/api/package.json @@ -28,6 +28,8 @@ "@nestjs/core": "^11.0.1", "@nestjs/platform-express": "^11.0.1", "@nestjs/swagger": "^11.2.7", + "class-transformer": "^0.5.1", + "class-validator": "^0.15.1", "mongoose": "^9.4.1", "nats": "^2.29.3", "reflect-metadata": "^0.2.2", diff --git a/apps/api/src/app.module.ts b/apps/api/src/app.module.ts index 45a79906..fed6dbfb 100644 --- a/apps/api/src/app.module.ts +++ b/apps/api/src/app.module.ts @@ -2,7 +2,11 @@ import { Module } from '@nestjs/common'; import { ConfigModule } from '@nestjs/config'; import { AppController } from './app.controller'; import { AppService } from './app.service'; +import { AuctionModule } from './modules/auction/auction.module'; +import { AuthModule } from './modules/auth/auth.module'; +import { CommunityModule } from './modules/community/community.module'; import { GlobalModule } from './modules/global/global.module'; +import { MatchModule } from './modules/match/match.module'; import { RiotModule } from './modules/riot/riot.module'; @Module({ @@ -12,7 +16,11 @@ import { RiotModule } from './modules/riot/riot.module'; envFilePath: ['../project.env', 'project.env'], }), GlobalModule, + AuthModule, RiotModule, + CommunityModule, + MatchModule, + AuctionModule, ], controllers: [AppController], providers: [AppService], diff --git a/apps/api/src/main.ts b/apps/api/src/main.ts index 5ee0da56..9cef9d3f 100644 --- a/apps/api/src/main.ts +++ b/apps/api/src/main.ts @@ -1,3 +1,4 @@ +import { ValidationPipe } from '@nestjs/common'; import { NestFactory } from '@nestjs/core'; import { AppModule } from './app.module'; @@ -5,6 +6,14 @@ async function bootstrap() { const app = await NestFactory.create(AppModule, { rawBody: true, }); + app.useGlobalPipes( + new ValidationPipe({ + whitelist: true, + forbidNonWhitelisted: true, + transform: true, + transformOptions: { enableImplicitConversion: false }, + }), + ); await app.listen(process.env.PORT ?? 3000); } bootstrap(); diff --git a/apps/api/src/modules/auction/auction.controller.ts b/apps/api/src/modules/auction/auction.controller.ts new file mode 100644 index 00000000..a526ecc7 --- /dev/null +++ b/apps/api/src/modules/auction/auction.controller.ts @@ -0,0 +1,134 @@ +import { + BadRequestException, + Body, + Controller, + Delete, + Get, + HttpCode, + HttpStatus, + Param, + Post, + UseGuards, +} from '@nestjs/common'; +import mongoose from 'mongoose'; +import { CurrentUser } from '../auth/current-user.decorator'; +import { Roles } from '../auth/roles.decorator'; +import { RolesGuard } from '../auth/roles.guard'; +import { ParseObjectIdPipe } from '../common/parse-object-id.pipe'; +import type { UserDocument } from '../global/database/schema'; +import { AuctionService } from './auction.service'; +import { PlaceBidDto, SoldDto, StartAuctionDto } from './dto/auction.dto'; + +@Controller('communities/:communityId/matches/:matchId/auction') +export class AuctionController { + constructor(private readonly auctionService: AuctionService) {} + + @Post() + @Roles('admin', 'owner') + @UseGuards(RolesGuard) + public async startAuction( + @CurrentUser() currentUser: UserDocument, + @Param('communityId', ParseObjectIdPipe) + communityId: mongoose.Types.ObjectId, + @Param('matchId', ParseObjectIdPipe) matchId: mongoose.Types.ObjectId, + @Body() body: StartAuctionDto, + ) { + this.assertSameCommunity(currentUser, communityId); + return this.auctionService.start({ + matchId, + communityId, + captains: body.captains.map((c) => ({ + side: c.side, + userId: new mongoose.Types.ObjectId(c.userId), + })), + initialPoints: body.initialPoints ?? 1000, + maxTimerSeconds: body.maxTimerSeconds ?? 30, + }); + } + + @Get() + public async getAuction( + @Param('matchId', ParseObjectIdPipe) matchId: mongoose.Types.ObjectId, + ) { + return this.auctionService.getByMatchId(matchId); + } + + // 공개 — 팀장 2명만 쓸 엔드포인트(트러스트 기반, 10명 동시 관전). + @Post('open-bidding') + @HttpCode(HttpStatus.OK) + public async openBidding( + @Param('matchId', ParseObjectIdPipe) matchId: mongoose.Types.ObjectId, + ) { + return this.auctionService.openBidding(matchId); + } + + @Post('bids') + @HttpCode(HttpStatus.OK) + public async placeBid( + @CurrentUser() currentUser: UserDocument | undefined, + @Param('matchId', ParseObjectIdPipe) matchId: mongoose.Types.ObjectId, + @Body() body: PlaceBidDto, + ) { + return this.auctionService.placeBid({ + matchId, + side: body.side, + amount: body.amount, + bidderUserId: this.resolveBidder(currentUser, body.bidderUserId), + }); + } + + @Post('sold') + @HttpCode(HttpStatus.OK) + public async markSold( + @Param('matchId', ParseObjectIdPipe) matchId: mongoose.Types.ObjectId, + @Body() body: SoldDto, + ) { + return this.auctionService.markSold({ + matchId, + assignedPosition: body.assignedPosition, + }); + } + + @Post('next') + @HttpCode(HttpStatus.OK) + public async next( + @Param('matchId', ParseObjectIdPipe) matchId: mongoose.Types.ObjectId, + ) { + return this.auctionService.next(matchId); + } + + @Delete() + @Roles('admin', 'owner') + @UseGuards(RolesGuard) + @HttpCode(HttpStatus.NO_CONTENT) + public async resetAuction( + @CurrentUser() currentUser: UserDocument, + @Param('communityId', ParseObjectIdPipe) + communityId: mongoose.Types.ObjectId, + @Param('matchId', ParseObjectIdPipe) matchId: mongoose.Types.ObjectId, + ) { + this.assertSameCommunity(currentUser, communityId); + await this.auctionService.reset({ matchId, communityId }); + } + + private resolveBidder( + currentUser: UserDocument | undefined, + bodyBidder?: string, + ): mongoose.Types.ObjectId | undefined { + if (currentUser) return currentUser._id; + if (!bodyBidder) return undefined; + if (!mongoose.isValidObjectId(bodyBidder)) { + throw new BadRequestException('Invalid bidderUserId.'); + } + return new mongoose.Types.ObjectId(bodyBidder); + } + + private assertSameCommunity( + user: UserDocument, + communityId: mongoose.Types.ObjectId, + ): void { + if (!user.communityId.equals(communityId)) { + throw new BadRequestException('Different community.'); + } + } +} diff --git a/apps/api/src/modules/auction/auction.module.ts b/apps/api/src/modules/auction/auction.module.ts new file mode 100644 index 00000000..82e38f62 --- /dev/null +++ b/apps/api/src/modules/auction/auction.module.ts @@ -0,0 +1,10 @@ +import { Module } from '@nestjs/common'; +import { AuctionController } from './auction.controller'; +import { AuctionService } from './auction.service'; + +@Module({ + controllers: [AuctionController], + providers: [AuctionService], + exports: [AuctionService], +}) +export class AuctionModule {} diff --git a/apps/api/src/modules/auction/auction.service.ts b/apps/api/src/modules/auction/auction.service.ts new file mode 100644 index 00000000..20f2e568 --- /dev/null +++ b/apps/api/src/modules/auction/auction.service.ts @@ -0,0 +1,265 @@ +import { + BadRequestException, + Injectable, + InternalServerErrorException, + NotFoundException, +} from '@nestjs/common'; +import mongoose from 'mongoose'; +import { ConnectionService } from '../global/database/connection.service'; +import { + AuctionDocument, + AuctionPlayerSnapshot, + Position, + TeamSide, +} from '../global/database/schema'; + +interface StartAuctionParams { + matchId: mongoose.Types.ObjectId; + communityId: mongoose.Types.ObjectId; + captains: { side: TeamSide; userId: mongoose.Types.ObjectId }[]; + initialPoints: number; + maxTimerSeconds: number; +} + +interface PlaceBidParams { + matchId: mongoose.Types.ObjectId; + side: TeamSide; + amount: number; + bidderUserId?: mongoose.Types.ObjectId; +} + +interface MarkSoldParams { + matchId: mongoose.Types.ObjectId; + assignedPosition?: Position; +} + +@Injectable() +export class AuctionService { + constructor(private readonly connectionService: ConnectionService) {} + + public async start(params: StartAuctionParams): Promise { + const MatchModel = await this.connectionService.getModel('match'); + const UserModel = await this.connectionService.getModel('user'); + const AuctionModel = await this.connectionService.getModel('auction'); + + const match = await MatchModel.findById(params.matchId); + if (!match) throw new NotFoundException('Match not found.'); + if (!match.communityId.equals(params.communityId)) { + throw new BadRequestException('Match does not belong to this community.'); + } + + const existing = await AuctionModel.findOne({ matchId: params.matchId }); + if (existing) { + throw new BadRequestException('Auction already exists for this match.'); + } + + const captainUserIds = params.captains.map((c) => c.userId); + if (captainUserIds[0].equals(captainUserIds[1])) { + throw new BadRequestException('Captains must be different users.'); + } + const captainParticipants = match.participants.filter((p) => + captainUserIds.some((cid) => cid.equals(p.userId)), + ); + if (captainParticipants.length !== 2) { + throw new BadRequestException( + 'Both captains must be participants of the match.', + ); + } + + const nonCaptainPuuids = new Set(); + const playerUsers = await UserModel.find({ + _id: { + $in: match.participants + .filter((p) => !captainUserIds.some((cid) => cid.equals(p.userId))) + .map((p) => p.userId), + }, + }); + const userById = new Map(playerUsers.map((u) => [u._id.toString(), u])); + + const order: AuctionPlayerSnapshot[] = []; + for (const participant of match.participants) { + if (captainUserIds.some((cid) => cid.equals(participant.userId))) { + continue; + } + const user = userById.get(participant.userId.toString()); + if (!user) continue; + const primary = + user.riotAccounts.find((a) => a.isPrimary) ?? user.riotAccounts[0]; + if (!primary) { + throw new BadRequestException( + `Participant ${user._id.toString()} has no Riot account.`, + ); + } + if (nonCaptainPuuids.has(primary.puuid)) continue; + nonCaptainPuuids.add(primary.puuid); + order.push({ + userId: user._id, + puuid: primary.puuid, + gameName: primary.gameName, + tagLine: primary.tagLine, + profileIconId: primary.profileIconId, + preferredPositions: participant.preferredPositions, + tiers: primary.tiers, + masteries: primary.championMasteries, + recentStatsSummary: primary.recentStatsSummary, + }); + } + + const auction = await AuctionModel.create({ + matchId: params.matchId, + phase: 'presenting', + teams: params.captains.map((c) => ({ + side: c.side, + captainUserId: c.userId, + points: params.initialPoints, + members: [], + })), + order, + currentIndex: 0, + bids: [], + currentBid: 0, + maxTimerSeconds: params.maxTimerSeconds, + initialPoints: params.initialPoints, + startedAt: new Date(), + }); + + match.status = 'team-built'; + await match.save(); + + return auction; + } + + public async getByMatchId( + matchId: mongoose.Types.ObjectId, + ): Promise { + const AuctionModel = await this.connectionService.getModel('auction'); + const auction = await AuctionModel.findOne({ matchId }); + if (!auction) throw new NotFoundException('Auction not found.'); + return auction; + } + + public async openBidding( + matchId: mongoose.Types.ObjectId, + ): Promise { + const auction = await this.getByMatchId(matchId); + if (auction.phase !== 'presenting') { + throw new BadRequestException('Auction is not in presenting phase.'); + } + auction.phase = 'bidding'; + auction.currentBid = 0; + auction.currentBidder = undefined; + await auction.save(); + return auction; + } + + public async placeBid(params: PlaceBidParams): Promise { + const auction = await this.getByMatchId(params.matchId); + if (auction.phase !== 'bidding') { + throw new BadRequestException('Auction is not in bidding phase.'); + } + const team = auction.teams.find((t) => t.side === params.side); + if (!team) throw new BadRequestException('Unknown team side.'); + if (params.amount <= auction.currentBid) { + throw new BadRequestException('Bid must exceed current bid.'); + } + if (params.amount > team.points) { + throw new BadRequestException('Bid exceeds team points.'); + } + + auction.currentBid = params.amount; + auction.currentBidder = params.side; + auction.bids.push({ + side: params.side, + amount: params.amount, + bidderUserId: params.bidderUserId ?? team.captainUserId, + timestamp: new Date(), + }); + await auction.save(); + return auction; + } + + public async markSold(params: MarkSoldParams): Promise { + const auction = await this.getByMatchId(params.matchId); + if (auction.phase !== 'bidding') { + throw new BadRequestException('Auction is not in bidding phase.'); + } + if (!auction.currentBidder || auction.currentBid <= 0) { + throw new BadRequestException('No bid to mark sold.'); + } + const team = auction.teams.find((t) => t.side === auction.currentBidder); + if (!team) throw new BadRequestException('Winning team not found.'); + + const current = auction.order[auction.currentIndex]; + if (!current) throw new BadRequestException('No current player.'); + + const preferredPrimary = current.preferredPositions[0]?.position; + team.members.push({ + userId: current.userId, + assignedPosition: params.assignedPosition ?? preferredPrimary ?? 'MID', + cost: auction.currentBid, + }); + team.points -= auction.currentBid; + auction.phase = 'sold'; + await auction.save(); + return auction; + } + + public async next( + matchId: mongoose.Types.ObjectId, + ): Promise { + const auction = await this.getByMatchId(matchId); + if (auction.phase !== 'sold' && auction.phase !== 'presenting') { + throw new BadRequestException('Cannot advance from current phase.'); + } + const nextIndex = auction.currentIndex + 1; + if (nextIndex >= auction.order.length) { + auction.phase = 'complete'; + auction.completedAt = new Date(); + } else { + auction.currentIndex = nextIndex; + auction.phase = 'presenting'; + auction.currentBid = 0; + auction.currentBidder = undefined; + } + await auction.save(); + return auction; + } + + public async reset(params: { + matchId: mongoose.Types.ObjectId; + communityId: mongoose.Types.ObjectId; + }): Promise { + const AuctionModel = await this.connectionService.getModel('auction'); + const MatchModel = await this.connectionService.getModel('match'); + + const session = await this.connectionService.createSession(); + if (!session) { + throw new InternalServerErrorException('Failed to start DB session.'); + } + try { + session.startTransaction(); + const auction = await AuctionModel.findOne({ + matchId: params.matchId, + }).session(session); + if (!auction) throw new NotFoundException('Auction not found.'); + + const match = await MatchModel.findById(params.matchId).session(session); + if (!match) throw new NotFoundException('Match not found.'); + if (!match.communityId.equals(params.communityId)) { + throw new BadRequestException('Community mismatch.'); + } + + await auction.deleteOne({ session }); + if (match.status === 'team-built') { + match.status = 'recruiting'; + await match.save({ session }); + } + await session.commitTransaction(); + } catch (err) { + await session.abortTransaction(); + throw err; + } finally { + await session.endSession(); + } + } +} diff --git a/apps/api/src/modules/auction/dto/auction.dto.ts b/apps/api/src/modules/auction/dto/auction.dto.ts new file mode 100644 index 00000000..9fee333d --- /dev/null +++ b/apps/api/src/modules/auction/dto/auction.dto.ts @@ -0,0 +1,60 @@ +import { Type } from 'class-transformer'; +import { + ArrayMaxSize, + ArrayMinSize, + IsArray, + IsEnum, + IsInt, + IsMongoId, + IsOptional, + Min, + ValidateNested, +} from 'class-validator'; +import { TEAM_SIDES } from '../../global/database/schema'; +import type { TeamSide } from '../../global/database/schema'; + +class CaptainAssignmentDto { + @IsEnum(TEAM_SIDES) + side!: TeamSide; + + @IsMongoId() + userId!: string; +} + +export class StartAuctionDto { + @IsArray() + @ArrayMinSize(2) + @ArrayMaxSize(2) + @ValidateNested({ each: true }) + @Type(() => CaptainAssignmentDto) + captains!: CaptainAssignmentDto[]; + + @IsOptional() + @IsInt() + @Min(1) + initialPoints?: number; + + @IsOptional() + @IsInt() + @Min(5) + maxTimerSeconds?: number; +} + +export class PlaceBidDto { + @IsEnum(TEAM_SIDES) + side!: TeamSide; + + @IsInt() + @Min(1) + amount!: number; + + @IsOptional() + @IsMongoId() + bidderUserId?: string; +} + +export class SoldDto { + @IsOptional() + @IsEnum(['TOP', 'JGL', 'MID', 'ADC', 'SUP']) + assignedPosition?: 'TOP' | 'JGL' | 'MID' | 'ADC' | 'SUP'; +} diff --git a/apps/api/src/modules/auth/auth.middleware.ts b/apps/api/src/modules/auth/auth.middleware.ts new file mode 100644 index 00000000..1c5db31e --- /dev/null +++ b/apps/api/src/modules/auth/auth.middleware.ts @@ -0,0 +1,21 @@ +import { Injectable, NestMiddleware } from '@nestjs/common'; +import type { NextFunction, Request, Response } from 'express'; +import { UserDocument } from '../global/database/schema'; +import { AuthService } from './auth.service'; + +declare module 'express' { + interface Request { + user?: UserDocument; + } +} + +@Injectable() +export class AuthMiddleware implements NestMiddleware { + constructor(private readonly authService: AuthService) {} + + public async use(req: Request, _res: Response, next: NextFunction) { + const user = await this.authService.resolveUserFromRequest(req); + if (user) req.user = user; + next(); + } +} diff --git a/apps/api/src/modules/auth/auth.module.ts b/apps/api/src/modules/auth/auth.module.ts new file mode 100644 index 00000000..643ee8db --- /dev/null +++ b/apps/api/src/modules/auth/auth.module.ts @@ -0,0 +1,15 @@ +import { Global, MiddlewareConsumer, Module, NestModule } from '@nestjs/common'; +import { AuthMiddleware } from './auth.middleware'; +import { AuthService } from './auth.service'; +import { RolesGuard } from './roles.guard'; + +@Global() +@Module({ + providers: [AuthService, RolesGuard], + exports: [AuthService, RolesGuard], +}) +export class AuthModule implements NestModule { + public configure(consumer: MiddlewareConsumer) { + consumer.apply(AuthMiddleware).forRoutes('*'); + } +} diff --git a/apps/api/src/modules/auth/auth.service.ts b/apps/api/src/modules/auth/auth.service.ts new file mode 100644 index 00000000..a6cb2cbf --- /dev/null +++ b/apps/api/src/modules/auth/auth.service.ts @@ -0,0 +1,23 @@ +import { Injectable } from '@nestjs/common'; +import type { Request } from 'express'; +import mongoose from 'mongoose'; +import { ConnectionService } from '../global/database/connection.service'; +import { UserDocument } from '../global/database/schema'; + +@Injectable() +export class AuthService { + constructor(private readonly connectionService: ConnectionService) {} + + // 로그인/세션 구현 전까지는 `X-Auth-User-Id` 헤더로 유저를 식별. + // OAuth 도입 시 이 메서드만 교체하면 됨. + public async resolveUserFromRequest( + req: Request, + ): Promise { + const header = req.headers['x-auth-user-id']; + const userId = Array.isArray(header) ? header[0] : header; + if (!userId || !mongoose.isValidObjectId(userId)) return null; + + const UserModel = await this.connectionService.getModel('user'); + return UserModel.findById(userId).exec(); + } +} diff --git a/apps/api/src/modules/auth/current-user.decorator.ts b/apps/api/src/modules/auth/current-user.decorator.ts new file mode 100644 index 00000000..9f4c159a --- /dev/null +++ b/apps/api/src/modules/auth/current-user.decorator.ts @@ -0,0 +1,9 @@ +import { createParamDecorator, ExecutionContext } from '@nestjs/common'; +import { UserDocument } from '../global/database/schema'; + +export const CurrentUser = createParamDecorator( + (_data: unknown, ctx: ExecutionContext): UserDocument | undefined => { + const req = ctx.switchToHttp().getRequest<{ user?: UserDocument }>(); + return req.user; + }, +); diff --git a/apps/api/src/modules/auth/permissions.ts b/apps/api/src/modules/auth/permissions.ts new file mode 100644 index 00000000..7e7f7800 --- /dev/null +++ b/apps/api/src/modules/auth/permissions.ts @@ -0,0 +1,35 @@ +import { CommunityRole } from '../global/database/schema'; + +export type Permission = + | 'community:edit' + | 'community:delete' + | 'community:transfer' + | 'user:role:manage' + | 'match:create' + | 'match:edit' + | 'match:delete' + | 'auction:manage'; + +type PermissionSet = readonly Permission[] | readonly ['*']; + +export const ROLE_PERMISSIONS: Record = { + owner: ['*'] as const, + admin: [ + 'community:edit', + 'user:role:manage', + 'match:create', + 'match:edit', + 'match:delete', + 'auction:manage', + ] as const, + member: [] as const, +}; + +export function roleHasPermission( + role: CommunityRole, + permission: Permission, +): boolean { + const perms = ROLE_PERMISSIONS[role]; + if (perms.length === 1 && perms[0] === '*') return true; + return (perms as readonly Permission[]).includes(permission); +} diff --git a/apps/api/src/modules/auth/roles.decorator.ts b/apps/api/src/modules/auth/roles.decorator.ts new file mode 100644 index 00000000..819cbb3a --- /dev/null +++ b/apps/api/src/modules/auth/roles.decorator.ts @@ -0,0 +1,7 @@ +import { SetMetadata } from '@nestjs/common'; +import { CommunityRole } from '../global/database/schema'; + +export const ROLES_KEY = 'lolympus:roles'; + +export const Roles = (...roles: CommunityRole[]) => + SetMetadata(ROLES_KEY, roles); diff --git a/apps/api/src/modules/auth/roles.guard.ts b/apps/api/src/modules/auth/roles.guard.ts new file mode 100644 index 00000000..c2ecaf72 --- /dev/null +++ b/apps/api/src/modules/auth/roles.guard.ts @@ -0,0 +1,32 @@ +import { + CanActivate, + ExecutionContext, + ForbiddenException, + Injectable, + UnauthorizedException, +} from '@nestjs/common'; +import { Reflector } from '@nestjs/core'; +import type { Request } from 'express'; +import { CommunityRole, UserDocument } from '../global/database/schema'; +import { ROLES_KEY } from './roles.decorator'; + +@Injectable() +export class RolesGuard implements CanActivate { + constructor(private readonly reflector: Reflector) {} + + public canActivate(context: ExecutionContext): boolean { + const requiredRoles = this.reflector.getAllAndOverride( + ROLES_KEY, + [context.getHandler(), context.getClass()], + ); + if (!requiredRoles || requiredRoles.length === 0) return true; + + const req = context.switchToHttp().getRequest(); + const user = req.user as UserDocument | undefined; + if (!user) throw new UnauthorizedException('Authentication required.'); + if (!requiredRoles.includes(user.role)) { + throw new ForbiddenException('Insufficient role.'); + } + return true; + } +} diff --git a/apps/api/src/modules/common/parse-object-id.pipe.ts b/apps/api/src/modules/common/parse-object-id.pipe.ts new file mode 100644 index 00000000..e9e046f6 --- /dev/null +++ b/apps/api/src/modules/common/parse-object-id.pipe.ts @@ -0,0 +1,24 @@ +import { + ArgumentMetadata, + BadRequestException, + Injectable, + PipeTransform, +} from '@nestjs/common'; +import mongoose from 'mongoose'; + +@Injectable() +export class ParseObjectIdPipe + implements PipeTransform +{ + public transform( + value: string, + metadata: ArgumentMetadata, + ): mongoose.Types.ObjectId { + if (!mongoose.isValidObjectId(value)) { + throw new BadRequestException( + `Invalid ObjectId for ${metadata.data ?? 'param'}.`, + ); + } + return new mongoose.Types.ObjectId(value); + } +} diff --git a/apps/api/src/modules/community/community.controller.ts b/apps/api/src/modules/community/community.controller.ts new file mode 100644 index 00000000..3b5d0095 --- /dev/null +++ b/apps/api/src/modules/community/community.controller.ts @@ -0,0 +1,80 @@ +import { + Body, + Controller, + ForbiddenException, + Param, + Patch, + Post, + UseGuards, +} from '@nestjs/common'; +import mongoose from 'mongoose'; +import { CurrentUser } from '../auth/current-user.decorator'; +import { Roles } from '../auth/roles.decorator'; +import { RolesGuard } from '../auth/roles.guard'; +import { ParseObjectIdPipe } from '../common/parse-object-id.pipe'; +import type { UserDocument } from '../global/database/schema'; +import { CommunityService } from './community.service'; +import { CreateCommunityDto } from './dto/create-community.dto'; +import { TransferOwnershipDto } from './dto/transfer-ownership.dto'; + +@Controller('communities') +export class CommunityController { + constructor(private readonly communityService: CommunityService) {} + + @Post() + public async createCommunity(@Body() body: CreateCommunityDto) { + return this.communityService.createCommunityWithOwner(body); + } + + @Patch(':communityId/members/:userId/promote') + @Roles('owner') + @UseGuards(RolesGuard) + public async promoteToAdmin( + @CurrentUser() currentUser: UserDocument, + @Param('communityId', ParseObjectIdPipe) + communityId: mongoose.Types.ObjectId, + @Param('userId', ParseObjectIdPipe) targetUserId: mongoose.Types.ObjectId, + ) { + this.assertOwnerOfCommunity(currentUser, communityId); + return this.communityService.promoteToAdmin({ communityId, targetUserId }); + } + + @Patch(':communityId/members/:userId/demote') + @Roles('owner') + @UseGuards(RolesGuard) + public async demoteToMember( + @CurrentUser() currentUser: UserDocument, + @Param('communityId', ParseObjectIdPipe) + communityId: mongoose.Types.ObjectId, + @Param('userId', ParseObjectIdPipe) targetUserId: mongoose.Types.ObjectId, + ) { + this.assertOwnerOfCommunity(currentUser, communityId); + return this.communityService.demoteToMember({ communityId, targetUserId }); + } + + @Patch(':communityId/transfer-ownership') + @Roles('owner') + @UseGuards(RolesGuard) + public async transferOwnership( + @CurrentUser() currentUser: UserDocument, + @Param('communityId', ParseObjectIdPipe) + communityId: mongoose.Types.ObjectId, + @Body() body: TransferOwnershipDto, + ) { + this.assertOwnerOfCommunity(currentUser, communityId); + return this.communityService.transferOwnership({ + communityId, + currentOwnerUserId: currentUser._id, + newOwnerUserId: new mongoose.Types.ObjectId(body.newOwnerUserId), + }); + } + + private assertOwnerOfCommunity( + user: UserDocument, + communityId: mongoose.Types.ObjectId, + ): void { + if (!user.communityId.equals(communityId)) { + throw new ForbiddenException('You do not belong to this community.'); + } + } +} diff --git a/apps/api/src/modules/community/community.module.ts b/apps/api/src/modules/community/community.module.ts new file mode 100644 index 00000000..24e60fd7 --- /dev/null +++ b/apps/api/src/modules/community/community.module.ts @@ -0,0 +1,10 @@ +import { Module } from '@nestjs/common'; +import { CommunityController } from './community.controller'; +import { CommunityService } from './community.service'; + +@Module({ + controllers: [CommunityController], + providers: [CommunityService], + exports: [CommunityService], +}) +export class CommunityModule {} diff --git a/apps/api/src/modules/community/community.service.ts b/apps/api/src/modules/community/community.service.ts new file mode 100644 index 00000000..eb1a5c79 --- /dev/null +++ b/apps/api/src/modules/community/community.service.ts @@ -0,0 +1,185 @@ +import { + BadRequestException, + Injectable, + InternalServerErrorException, + NotFoundException, +} from '@nestjs/common'; +import mongoose from 'mongoose'; +import { ConnectionService } from '../global/database/connection.service'; +import { + CommunityDocument, + UserDocument, +} from '../global/database/schema'; + +export interface CreateCommunityInput { + name: string; + description?: string; + owner: { + kakaoTalkId?: string; + kakaoTalkNickname?: string; + discordId?: string; + discordNickname?: string; + }; +} + +@Injectable() +export class CommunityService { + constructor(private readonly connectionService: ConnectionService) {} + + public async createCommunityWithOwner(input: CreateCommunityInput): Promise<{ + community: CommunityDocument; + owner: UserDocument; + }> { + const CommunityModel = await this.connectionService.getModel('community'); + const UserModel = await this.connectionService.getModel('user'); + + const communityId = new mongoose.Types.ObjectId(); + const ownerUserId = new mongoose.Types.ObjectId(); + + const session = await this.connectionService.createSession(); + if (!session) { + throw new InternalServerErrorException('Failed to start DB session.'); + } + + try { + session.startTransaction(); + + const [community] = await CommunityModel.create( + [ + { + _id: communityId, + name: input.name, + description: input.description ?? '', + ownerUserId, + }, + ], + { session }, + ); + + const [owner] = await UserModel.create( + [ + { + _id: ownerUserId, + communityId, + role: 'owner', + kakaoTalkId: input.owner.kakaoTalkId, + kakaoTalkNickname: input.owner.kakaoTalkNickname, + discordId: input.owner.discordId, + discordNickname: input.owner.discordNickname, + }, + ], + { session }, + ); + + await session.commitTransaction(); + return { community, owner }; + } catch (err) { + await session.abortTransaction(); + throw err; + } finally { + await session.endSession(); + } + } + + public async promoteToAdmin(params: { + communityId: mongoose.Types.ObjectId; + targetUserId: mongoose.Types.ObjectId; + }): Promise { + return this.changeNonOwnerRole({ ...params, nextRole: 'admin' }); + } + + public async demoteToMember(params: { + communityId: mongoose.Types.ObjectId; + targetUserId: mongoose.Types.ObjectId; + }): Promise { + return this.changeNonOwnerRole({ ...params, nextRole: 'member' }); + } + + public async transferOwnership(params: { + communityId: mongoose.Types.ObjectId; + currentOwnerUserId: mongoose.Types.ObjectId; + newOwnerUserId: mongoose.Types.ObjectId; + }): Promise<{ + community: CommunityDocument; + previousOwner: UserDocument; + newOwner: UserDocument; + }> { + if (params.currentOwnerUserId.equals(params.newOwnerUserId)) { + throw new BadRequestException('New owner is already the current owner.'); + } + + const CommunityModel = await this.connectionService.getModel('community'); + const UserModel = await this.connectionService.getModel('user'); + + const session = await this.connectionService.createSession(); + if (!session) { + throw new InternalServerErrorException('Failed to start DB session.'); + } + + try { + session.startTransaction(); + + const community = await CommunityModel.findById( + params.communityId, + ).session(session); + if (!community) throw new NotFoundException('Community not found.'); + if (!community.ownerUserId.equals(params.currentOwnerUserId)) { + throw new BadRequestException('Acting user is not the current owner.'); + } + + const [previousOwner, newOwner] = await Promise.all([ + UserModel.findById(params.currentOwnerUserId).session(session), + UserModel.findById(params.newOwnerUserId).session(session), + ]); + if (!previousOwner) + throw new NotFoundException('Previous owner user not found.'); + if (!newOwner) throw new NotFoundException('New owner user not found.'); + if (!newOwner.communityId.equals(params.communityId)) { + throw new BadRequestException( + 'New owner does not belong to this community.', + ); + } + + community.ownerUserId = newOwner._id; + previousOwner.role = 'admin'; + newOwner.role = 'owner'; + + await Promise.all([ + community.save({ session }), + previousOwner.save({ session }), + newOwner.save({ session }), + ]); + + await session.commitTransaction(); + return { community, previousOwner, newOwner }; + } catch (err) { + await session.abortTransaction(); + throw err; + } finally { + await session.endSession(); + } + } + + private async changeNonOwnerRole(params: { + communityId: mongoose.Types.ObjectId; + targetUserId: mongoose.Types.ObjectId; + nextRole: 'admin' | 'member'; + }): Promise { + const UserModel = await this.connectionService.getModel('user'); + const user = await UserModel.findById(params.targetUserId); + if (!user) throw new NotFoundException('Target user not found.'); + if (!user.communityId.equals(params.communityId)) { + throw new BadRequestException( + 'Target user does not belong to this community.', + ); + } + if (user.role === 'owner') { + throw new BadRequestException( + 'Owner role must be changed via transferOwnership.', + ); + } + user.role = params.nextRole; + await user.save(); + return user; + } +} diff --git a/apps/api/src/modules/community/dto/create-community.dto.ts b/apps/api/src/modules/community/dto/create-community.dto.ts new file mode 100644 index 00000000..80d62588 --- /dev/null +++ b/apps/api/src/modules/community/dto/create-community.dto.ts @@ -0,0 +1,46 @@ +import { Type } from 'class-transformer'; +import { + IsOptional, + IsString, + MaxLength, + MinLength, + ValidateNested, +} from 'class-validator'; + +class CreateCommunityOwnerDto { + @IsOptional() + @IsString() + @MaxLength(64) + kakaoTalkId?: string; + + @IsOptional() + @IsString() + @MaxLength(64) + kakaoTalkNickname?: string; + + @IsOptional() + @IsString() + @MaxLength(64) + discordId?: string; + + @IsOptional() + @IsString() + @MaxLength(64) + discordNickname?: string; +} + +export class CreateCommunityDto { + @IsString() + @MinLength(1) + @MaxLength(64) + name!: string; + + @IsOptional() + @IsString() + @MaxLength(1024) + description?: string; + + @ValidateNested() + @Type(() => CreateCommunityOwnerDto) + owner!: CreateCommunityOwnerDto; +} diff --git a/apps/api/src/modules/community/dto/transfer-ownership.dto.ts b/apps/api/src/modules/community/dto/transfer-ownership.dto.ts new file mode 100644 index 00000000..90d472ec --- /dev/null +++ b/apps/api/src/modules/community/dto/transfer-ownership.dto.ts @@ -0,0 +1,6 @@ +import { IsMongoId } from 'class-validator'; + +export class TransferOwnershipDto { + @IsMongoId() + newOwnerUserId!: string; +} diff --git a/apps/api/src/modules/global/database/connection.service.ts b/apps/api/src/modules/global/database/connection.service.ts index 68396e2d..b92be6f2 100644 --- a/apps/api/src/modules/global/database/connection.service.ts +++ b/apps/api/src/modules/global/database/connection.service.ts @@ -1,10 +1,7 @@ import { Injectable, Scope, OnModuleInit } from '@nestjs/common'; import mongoose from 'mongoose'; import { SecretService } from '../secret/secret.service'; -import { - tournamentModelDefinitions, - TournamentModelTypes, -} from './schema'; +import { tournamentModelDefinitions, TournamentModelTypes } from './schema'; @Injectable({ scope: Scope.DEFAULT }) export class ConnectionService implements OnModuleInit { @@ -23,7 +20,7 @@ export class ConnectionService implements OnModuleInit { ); const defaultConnection = await mongoose .createConnection(connectionString, { - dbName: 'tournament', + dbName: 'lolympus', minPoolSize: 10, maxPoolSize: 20, }) diff --git a/apps/api/src/modules/global/database/schema.ts b/apps/api/src/modules/global/database/schema.ts index fe51cbd6..b65872e0 100644 --- a/apps/api/src/modules/global/database/schema.ts +++ b/apps/api/src/modules/global/database/schema.ts @@ -19,6 +19,14 @@ export const MATCH_STATUSES: MatchStatus[] = [ export type TeamSide = 'blue' | 'red'; export const TEAM_SIDES: TeamSide[] = ['blue', 'red']; +export type CommunityRole = 'owner' | 'admin' | 'member'; +export const COMMUNITY_ROLES: CommunityRole[] = ['owner', 'admin', 'member']; + +export interface PositionPreference { + position: Position; + priority: number; // 1 = 최우선, 숫자가 작을수록 높은 우선순위 +} + export type AuctionPhase = | 'waiting' | 'presenting' @@ -119,15 +127,24 @@ export interface RiotAccount extends MongooseTimestamps { // ===== User ===== export interface User extends MongooseTimestamps { + communityId: mongoose.Types.ObjectId; + role: CommunityRole; kakaoTalkId?: string; kakaoTalkNickname?: string; discordId?: string; discordNickname?: string; riotAccounts: RiotAccount[]; - preferredPositions: Position[]; + preferredPositions: PositionPreference[]; isActivated: boolean; } +export interface Community extends MongooseTimestamps { + name: string; + description: string; + ownerUserId: mongoose.Types.ObjectId; +} + +export type CommunityDocument = HydratedDocument; export type UserDocument = HydratedDocument; // ===== RiotMatch (Riot 원본 매치 아카이브) ===== @@ -152,7 +169,7 @@ export interface MatchParticipant { gameName?: string; tagLine?: string; profileIconId?: number; - preferredPositions: Position[]; + preferredPositions: PositionPreference[]; joinedAt: Date; } @@ -183,9 +200,10 @@ export interface MatchScheduleItem { } export interface Match extends MongooseTimestamps { + communityId: mongoose.Types.ObjectId; title: string; description: string; - map: string; + mapId: number; // Riot Match-V5 mapId (11=소환사의 협곡, 12=ARAM 등) status: MatchStatus; scheduledAt: Date; maxParticipants: number; @@ -208,7 +226,7 @@ export interface AuctionPlayerSnapshot { gameName: string; tagLine: string; profileIconId: number; - preferredPositions: Position[]; + preferredPositions: PositionPreference[]; tiers: TierInfo[]; masteries: ChampionMasteryEntry[]; recentStatsSummary?: RiotRecentStatsSummary; @@ -230,7 +248,7 @@ export interface AuctionTeam { export interface AuctionBid { side: TeamSide; amount: number; - bidderUserId?: mongoose.Types.ObjectId; + bidderUserId: mongoose.Types.ObjectId; timestamp: Date; } @@ -252,6 +270,14 @@ export interface Auction extends MongooseTimestamps { export type AuctionDocument = HydratedDocument; // ===== Sub-schemas ===== +const PositionPreferenceSubSchema = new Schema( + { + position: { type: String, enum: POSITIONS, required: true }, + priority: { type: Number, required: true, min: 1 }, + }, + { _id: false }, +); + const TierInfoSubSchema = new Schema( { queueType: { type: String, required: true }, @@ -346,8 +372,34 @@ const RiotAccountSubSchema = new Schema( }, ); +export const CommunitySchema = new Schema( + { + name: { type: String, required: true }, + description: { type: String, required: true, default: '' }, + ownerUserId: { type: Schema.Types.ObjectId, ref: 'user', required: true }, + }, + { + timestamps: true, + collection: 'community', + }, +); + +CommunitySchema.index({ name: 1 }, { unique: true }); +CommunitySchema.index({ ownerUserId: 1 }); + export const UserSchema = new Schema( { + communityId: { + type: Schema.Types.ObjectId, + ref: 'community', + required: true, + }, + role: { + type: String, + enum: COMMUNITY_ROLES, + required: true, + default: 'member', + }, kakaoTalkId: { type: String }, kakaoTalkNickname: { type: String }, discordId: { type: String }, @@ -376,7 +428,7 @@ export const UserSchema = new Schema( ], }, preferredPositions: { - type: [{ type: String, enum: POSITIONS }], + type: [PositionPreferenceSubSchema], required: true, default: [], }, @@ -388,9 +440,20 @@ export const UserSchema = new Schema( }, ); -UserSchema.index({ kakaoTalkId: 1 }, { unique: true, sparse: true }); -UserSchema.index({ discordId: 1 }, { unique: true, sparse: true }); -UserSchema.index({ 'riotAccounts.puuid': 1 }, { unique: true, sparse: true }); +UserSchema.index({ communityId: 1 }); +UserSchema.index({ communityId: 1, role: 1 }); +UserSchema.index( + { communityId: 1, kakaoTalkId: 1 }, + { unique: true, sparse: true }, +); +UserSchema.index( + { communityId: 1, discordId: 1 }, + { unique: true, sparse: true }, +); +UserSchema.index( + { communityId: 1, 'riotAccounts.puuid': 1 }, + { unique: true, sparse: true }, +); export const RiotMatchSchema = new Schema( { @@ -419,7 +482,7 @@ const MatchParticipantSubSchema = new Schema( tagLine: { type: String }, profileIconId: { type: Number }, preferredPositions: { - type: [{ type: String, enum: POSITIONS }], + type: [PositionPreferenceSubSchema], required: true, default: [], }, @@ -468,9 +531,14 @@ const MatchScheduleItemSubSchema = new Schema( export const MatchSchema = new Schema( { + communityId: { + type: Schema.Types.ObjectId, + ref: 'community', + required: true, + }, title: { type: String, required: true }, description: { type: String, required: true, default: '' }, - map: { type: String, required: true, default: '소환사의 협곡' }, + mapId: { type: Number, required: true, default: 11 }, status: { type: String, enum: MATCH_STATUSES, @@ -508,8 +576,8 @@ export const MatchSchema = new Schema( }, ); -MatchSchema.index({ scheduledAt: -1 }); -MatchSchema.index({ status: 1, scheduledAt: -1 }); +MatchSchema.index({ communityId: 1, scheduledAt: -1 }); +MatchSchema.index({ communityId: 1, status: 1, scheduledAt: -1 }); MatchSchema.index({ title: 'text', description: 'text' }); const AuctionPlayerSnapshotSubSchema = new Schema( @@ -520,7 +588,7 @@ const AuctionPlayerSnapshotSubSchema = new Schema( tagLine: { type: String, required: true }, profileIconId: { type: Number, required: true, default: 0 }, preferredPositions: { - type: [{ type: String, enum: POSITIONS }], + type: [PositionPreferenceSubSchema], required: true, default: [], }, @@ -562,7 +630,7 @@ const AuctionBidSubSchema = new Schema( { side: { type: String, enum: TEAM_SIDES, required: true }, amount: { type: Number, required: true }, - bidderUserId: { type: Schema.Types.ObjectId, ref: 'user' }, + bidderUserId: { type: Schema.Types.ObjectId, ref: 'user', required: true }, timestamp: { type: Date, required: true, default: Date.now }, }, { _id: false }, @@ -604,6 +672,7 @@ export const AuctionSchema = new Schema( ); export const tournamentModelDefinitions: ModelDefinition[] = [ + { name: 'community', schema: CommunitySchema, schemaName: 'community' }, { name: 'user', schema: UserSchema, schemaName: 'user' }, { name: 'riotMatch', schema: RiotMatchSchema, schemaName: 'riotMatch' }, { name: 'match', schema: MatchSchema, schemaName: 'match' }, @@ -611,6 +680,7 @@ export const tournamentModelDefinitions: ModelDefinition[] = [ ]; export interface TournamentModelTypes { + community: Community; user: User; riotMatch: RiotMatch; match: Match; diff --git a/apps/api/src/modules/match/dto/create-match.dto.ts b/apps/api/src/modules/match/dto/create-match.dto.ts new file mode 100644 index 00000000..611b1e2e --- /dev/null +++ b/apps/api/src/modules/match/dto/create-match.dto.ts @@ -0,0 +1,135 @@ +import { Type } from 'class-transformer'; +import { + ArrayMaxSize, + ArrayMinSize, + IsArray, + IsDate, + IsEnum, + IsInt, + IsOptional, + IsString, + MaxLength, + Min, + MinLength, + ValidateNested, +} from 'class-validator'; +import { POSITIONS } from '../../global/database/schema'; +import type { Position } from '../../global/database/schema'; + +export class PositionPreferenceDto { + @IsEnum(POSITIONS) + position!: Position; + + @IsInt() + @Min(1) + priority!: number; +} + +class MatchScheduleItemDto { + @IsString() + @MaxLength(32) + time!: string; + + @IsString() + @MaxLength(128) + label!: string; +} + +export class CreateMatchDto { + @IsString() + @MinLength(1) + @MaxLength(128) + title!: string; + + @IsOptional() + @IsString() + @MaxLength(2048) + description?: string; + + @IsOptional() + @IsInt() + mapId?: number; + + @IsDate() + @Type(() => Date) + scheduledAt!: Date; + + @IsOptional() + @IsInt() + @Min(2) + maxParticipants?: number; + + @IsOptional() + @IsArray() + @IsString({ each: true }) + @ArrayMaxSize(32) + prizes?: string[]; + + @IsOptional() + @IsArray() + @IsString({ each: true }) + @ArrayMaxSize(32) + notices?: string[]; + + @IsOptional() + @IsArray() + @ValidateNested({ each: true }) + @Type(() => MatchScheduleItemDto) + @ArrayMaxSize(32) + schedule?: MatchScheduleItemDto[]; +} + +export class UpdateMatchDto { + @IsOptional() + @IsString() + @MaxLength(128) + title?: string; + + @IsOptional() + @IsString() + @MaxLength(2048) + description?: string; + + @IsOptional() + @IsInt() + mapId?: number; + + @IsOptional() + @IsDate() + @Type(() => Date) + scheduledAt?: Date; + + @IsOptional() + @IsInt() + @Min(2) + maxParticipants?: number; + + @IsOptional() + @IsArray() + @IsString({ each: true }) + prizes?: string[]; + + @IsOptional() + @IsArray() + @IsString({ each: true }) + notices?: string[]; + + @IsOptional() + @IsArray() + @ValidateNested({ each: true }) + @Type(() => MatchScheduleItemDto) + schedule?: MatchScheduleItemDto[]; +} + +export class JoinMatchDto { + @IsArray() + @ArrayMinSize(1) + @ArrayMaxSize(5) + @ValidateNested({ each: true }) + @Type(() => PositionPreferenceDto) + preferredPositions!: PositionPreferenceDto[]; + + @IsOptional() + @IsString() + userId?: string; +} diff --git a/apps/api/src/modules/match/match.controller.ts b/apps/api/src/modules/match/match.controller.ts new file mode 100644 index 00000000..af332904 --- /dev/null +++ b/apps/api/src/modules/match/match.controller.ts @@ -0,0 +1,163 @@ +import { + BadRequestException, + Body, + Controller, + Delete, + Get, + HttpCode, + HttpStatus, + Param, + Patch, + Post, + Query, + UseGuards, +} from '@nestjs/common'; +import mongoose from 'mongoose'; +import { CurrentUser } from '../auth/current-user.decorator'; +import { Roles } from '../auth/roles.decorator'; +import { RolesGuard } from '../auth/roles.guard'; +import { ParseObjectIdPipe } from '../common/parse-object-id.pipe'; +import type { + MatchDocument, + MatchStatus, + UserDocument, +} from '../global/database/schema'; +import { + CreateMatchDto, + JoinMatchDto, + UpdateMatchDto, +} from './dto/create-match.dto'; +import { MatchService } from './match.service'; + +@Controller('communities/:communityId/matches') +export class MatchController { + constructor(private readonly matchService: MatchService) {} + + @Post() + @Roles('admin', 'owner') + @UseGuards(RolesGuard) + public async createMatch( + @CurrentUser() currentUser: UserDocument, + @Param('communityId', ParseObjectIdPipe) + communityId: mongoose.Types.ObjectId, + @Body() body: CreateMatchDto, + ) { + this.assertSameCommunity(currentUser, communityId); + return this.matchService.create({ + communityId, + hostUserId: currentUser._id, + data: { + title: body.title, + description: body.description ?? '', + mapId: body.mapId ?? 11, + scheduledAt: body.scheduledAt, + maxParticipants: body.maxParticipants ?? 10, + prizes: body.prizes ?? [], + notices: body.notices ?? [], + schedule: body.schedule ?? [], + }, + }); + } + + // 공개 — 커뮤니티 내 매치 리스트. 로그인 시 본인 참여 여부를 함께 반환. + @Get() + public async listMatches( + @CurrentUser() currentUser: UserDocument | undefined, + @Param('communityId', ParseObjectIdPipe) + communityId: mongoose.Types.ObjectId, + @Query('status') status?: MatchStatus, + @Query('limit') limit?: string, + ) { + const matches = await this.matchService.list({ + communityId, + status, + limit: limit ? Number(limit) : undefined, + }); + if (!currentUser) return { matches }; + const myId = currentUser._id; + return { + matches: matches.map((m) => this.annotateJoined(m, myId)), + }; + } + + @Get(':matchId') + public async getMatch( + @Param('matchId', ParseObjectIdPipe) matchId: mongoose.Types.ObjectId, + ) { + return this.matchService.getById(matchId); + } + + @Patch(':matchId') + @Roles('admin', 'owner') + @UseGuards(RolesGuard) + public async updateMatch( + @CurrentUser() currentUser: UserDocument, + @Param('communityId', ParseObjectIdPipe) + communityId: mongoose.Types.ObjectId, + @Param('matchId', ParseObjectIdPipe) matchId: mongoose.Types.ObjectId, + @Body() body: UpdateMatchDto, + ) { + this.assertSameCommunity(currentUser, communityId); + return this.matchService.update({ matchId, communityId, patch: body }); + } + + @Delete(':matchId') + @Roles('admin', 'owner') + @UseGuards(RolesGuard) + @HttpCode(HttpStatus.NO_CONTENT) + public async deleteMatch( + @CurrentUser() currentUser: UserDocument, + @Param('communityId', ParseObjectIdPipe) + communityId: mongoose.Types.ObjectId, + @Param('matchId', ParseObjectIdPipe) matchId: mongoose.Types.ObjectId, + ) { + this.assertSameCommunity(currentUser, communityId); + await this.matchService.remove({ matchId, communityId }); + } + + // 공개 — 참여 (로그인된 유저는 자기 자신, 비로그인은 body.userId 사용). + @Post(':matchId/participants') + public async joinMatch( + @CurrentUser() currentUser: UserDocument | undefined, + @Param('matchId', ParseObjectIdPipe) matchId: mongoose.Types.ObjectId, + @Body() body: JoinMatchDto, + ) { + const userId = this.resolveJoinerUserId(currentUser, body.userId); + return this.matchService.join({ + matchId, + userId, + preferredPositions: body.preferredPositions, + }); + } + + 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 annotateJoined( + match: MatchDocument, + userId: mongoose.Types.ObjectId, + ) { + const obj = match.toObject(); + const joined = match.participants.some((p) => p.userId.equals(userId)); + return { ...obj, joined }; + } + + private assertSameCommunity( + user: UserDocument, + communityId: mongoose.Types.ObjectId, + ): void { + if (!user.communityId.equals(communityId)) { + throw new BadRequestException('Different community.'); + } + } +} diff --git a/apps/api/src/modules/match/match.module.ts b/apps/api/src/modules/match/match.module.ts new file mode 100644 index 00000000..6ead6da7 --- /dev/null +++ b/apps/api/src/modules/match/match.module.ts @@ -0,0 +1,10 @@ +import { Module } from '@nestjs/common'; +import { MatchController } from './match.controller'; +import { MatchService } from './match.service'; + +@Module({ + controllers: [MatchController], + providers: [MatchService], + exports: [MatchService], +}) +export class MatchModule {} diff --git a/apps/api/src/modules/match/match.service.ts b/apps/api/src/modules/match/match.service.ts new file mode 100644 index 00000000..20a0a20c --- /dev/null +++ b/apps/api/src/modules/match/match.service.ts @@ -0,0 +1,138 @@ +import { + BadRequestException, + Injectable, + NotFoundException, +} from '@nestjs/common'; +import mongoose from 'mongoose'; +import { ConnectionService } from '../global/database/connection.service'; +import { + Match, + MatchDocument, + MatchStatus, + PositionPreference, +} from '../global/database/schema'; + +interface CreateMatchParams { + communityId: mongoose.Types.ObjectId; + hostUserId?: mongoose.Types.ObjectId; + data: Partial & Pick; +} + +interface UpdateMatchParams { + matchId: mongoose.Types.ObjectId; + communityId: mongoose.Types.ObjectId; + patch: Partial; +} + +interface ListMatchesQuery { + communityId: mongoose.Types.ObjectId; + status?: MatchStatus; + limit?: number; +} + +interface JoinMatchParams { + matchId: mongoose.Types.ObjectId; + userId: mongoose.Types.ObjectId; + preferredPositions: PositionPreference[]; +} + +@Injectable() +export class MatchService { + constructor(private readonly connectionService: ConnectionService) {} + + public async create(params: CreateMatchParams): Promise { + const MatchModel = await this.connectionService.getModel('match'); + return MatchModel.create({ + ...params.data, + communityId: params.communityId, + hostUserId: params.hostUserId, + }); + } + + public async list(query: ListMatchesQuery): Promise { + const MatchModel = await this.connectionService.getModel('match'); + const filter: mongoose.FilterQuery = { + communityId: query.communityId, + }; + if (query.status) filter.status = query.status; + return MatchModel.find(filter) + .sort({ scheduledAt: -1 }) + .limit(Math.min(query.limit ?? 50, 200)) + .exec(); + } + + public async getById( + matchId: mongoose.Types.ObjectId, + ): Promise { + const MatchModel = await this.connectionService.getModel('match'); + const match = await MatchModel.findById(matchId); + if (!match) throw new NotFoundException('Match not found.'); + return match; + } + + public async update(params: UpdateMatchParams): Promise { + const MatchModel = await this.connectionService.getModel('match'); + const match = await MatchModel.findById(params.matchId); + if (!match) throw new NotFoundException('Match not found.'); + if (!match.communityId.equals(params.communityId)) { + throw new BadRequestException('Match does not belong to this community.'); + } + match.set(params.patch); + await match.save(); + return match; + } + + public async remove(params: { + matchId: mongoose.Types.ObjectId; + communityId: mongoose.Types.ObjectId; + }): Promise { + const MatchModel = await this.connectionService.getModel('match'); + const match = await MatchModel.findById(params.matchId); + if (!match) throw new NotFoundException('Match not found.'); + if (!match.communityId.equals(params.communityId)) { + throw new BadRequestException('Match does not belong to this community.'); + } + await match.deleteOne(); + } + + public async join(params: JoinMatchParams): Promise { + 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.'); + } + if (match.participants.length >= match.maxParticipants) { + throw new BadRequestException('Match is full.'); + } + const alreadyIn = match.participants.some((p) => + p.userId.equals(user._id), + ); + if (alreadyIn) { + throw new BadRequestException('User already joined this match.'); + } + + const primaryRiot = user.riotAccounts.find((a) => a.isPrimary); + match.participants.push({ + userId: user._id, + puuid: primaryRiot?.puuid, + gameName: primaryRiot?.gameName, + tagLine: primaryRiot?.tagLine, + profileIconId: primaryRiot?.profileIconId, + preferredPositions: params.preferredPositions, + joinedAt: new Date(), + }); + await match.save(); + return match; + } +} diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 10334635..f20da3a9 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -16,19 +16,25 @@ importers: dependencies: '@nestjs/common': specifier: ^11.0.1 - version: 11.1.18(reflect-metadata@0.2.2)(rxjs@7.8.2) + version: 11.1.18(class-transformer@0.5.1)(class-validator@0.15.1)(reflect-metadata@0.2.2)(rxjs@7.8.2) '@nestjs/config': specifier: ^4.0.4 - version: 4.0.4(@nestjs/common@11.1.18(reflect-metadata@0.2.2)(rxjs@7.8.2))(rxjs@7.8.2) + version: 4.0.4(@nestjs/common@11.1.18(class-transformer@0.5.1)(class-validator@0.15.1)(reflect-metadata@0.2.2)(rxjs@7.8.2))(rxjs@7.8.2) '@nestjs/core': specifier: ^11.0.1 - version: 11.1.18(@nestjs/common@11.1.18(reflect-metadata@0.2.2)(rxjs@7.8.2))(@nestjs/platform-express@11.1.18)(reflect-metadata@0.2.2)(rxjs@7.8.2) + version: 11.1.18(@nestjs/common@11.1.18(class-transformer@0.5.1)(class-validator@0.15.1)(reflect-metadata@0.2.2)(rxjs@7.8.2))(@nestjs/platform-express@11.1.18)(reflect-metadata@0.2.2)(rxjs@7.8.2) '@nestjs/platform-express': specifier: ^11.0.1 - version: 11.1.18(@nestjs/common@11.1.18(reflect-metadata@0.2.2)(rxjs@7.8.2))(@nestjs/core@11.1.18) + version: 11.1.18(@nestjs/common@11.1.18(class-transformer@0.5.1)(class-validator@0.15.1)(reflect-metadata@0.2.2)(rxjs@7.8.2))(@nestjs/core@11.1.18) '@nestjs/swagger': specifier: ^11.2.7 - version: 11.2.7(@nestjs/common@11.1.18(reflect-metadata@0.2.2)(rxjs@7.8.2))(@nestjs/core@11.1.18)(reflect-metadata@0.2.2) + version: 11.2.7(@nestjs/common@11.1.18(class-transformer@0.5.1)(class-validator@0.15.1)(reflect-metadata@0.2.2)(rxjs@7.8.2))(@nestjs/core@11.1.18)(class-transformer@0.5.1)(class-validator@0.15.1)(reflect-metadata@0.2.2) + class-transformer: + specifier: ^0.5.1 + version: 0.5.1 + class-validator: + specifier: ^0.15.1 + version: 0.15.1 mongoose: specifier: ^9.4.1 version: 9.4.1(@aws-sdk/credential-providers@3.993.0) @@ -59,7 +65,7 @@ importers: version: 11.0.10(chokidar@4.0.3)(typescript@5.9.3) '@nestjs/testing': specifier: ^11.0.1 - version: 11.1.18(@nestjs/common@11.1.18(reflect-metadata@0.2.2)(rxjs@7.8.2))(@nestjs/core@11.1.18)(@nestjs/platform-express@11.1.18) + version: 11.1.18(@nestjs/common@11.1.18(class-transformer@0.5.1)(class-validator@0.15.1)(reflect-metadata@0.2.2)(rxjs@7.8.2))(@nestjs/core@11.1.18)(@nestjs/platform-express@11.1.18) '@types/express': specifier: ^5.0.0 version: 5.0.6 @@ -1459,6 +1465,9 @@ packages: '@types/supertest@7.2.0': resolution: {integrity: sha512-uh2Lv57xvggst6lCqNdFAmDSvoMG7M/HDtX4iUCquxQ5EGPtaPM5PL5Hmi7LCvOG8db7YaCPNJEeoI8s/WzIQw==} + '@types/validator@13.15.10': + resolution: {integrity: sha512-T8L6i7wCuyoK8A/ZeLYt1+q0ty3Zb9+qbSSvrIVitzT3YjZqkTZ40IbRsPanlB4h1QB3JVL1SYCdR6ngtFYcuA==} + '@types/webidl-conversions@7.0.3': resolution: {integrity: sha512-CiJJvcRtIgzadHCYXw7dqEnMNRjhGZlYK05Mj9OyktqV8uVT8fD2BFOB7S1uwBE3Kj2Z+4UyPmFw/Ixgw/LAlA==} @@ -1951,6 +1960,12 @@ packages: cjs-module-lexer@2.2.0: resolution: {integrity: sha512-4bHTS2YuzUvtoLjdy+98ykbNB5jS0+07EvFNXerqZQJ89F7DI6ET7OQo/HJuW6K0aVsKA9hj9/RVb2kQVOrPDQ==} + class-transformer@0.5.1: + resolution: {integrity: sha512-SQa1Ws6hUbfC98vKGxZH3KFY0Y1lm5Zm0SY8XX9zbK7FJCyVEac3ATW0RIpwzW+oOfmHE5PMPufDG9hCfoEOMw==} + + class-validator@0.15.1: + resolution: {integrity: sha512-LqoS80HBBSCVhz/3KloUly0ovokxpdOLR++Al3J3+dHXWt9sTKlKd4eYtoxhxyUjoe5+UcIM+5k9MIxyBWnRTw==} + cli-cursor@3.1.0: resolution: {integrity: sha512-I/zHAwsKf9FqGoXM4WWRACob9+SNukZTd94DWF57E4toouRulbCxcUh6RKUEOQlYTHJnzkPMySvPNaaSLNfLZw==} engines: {node: '>=8'} @@ -2833,6 +2848,9 @@ packages: resolution: {integrity: sha512-+bT2uH4E5LGE7h/n3evcS/sQlJXCpIp6ym8OWJ5eV6+67Dsql/LaaT7qJBAt2rzfoa/5QBGBhxDix1dMt2kQKQ==} engines: {node: '>= 0.8.0'} + libphonenumber-js@1.12.42: + resolution: {integrity: sha512-oKQFPTibqQwZZkChCDVMFVJXMZdyJNqDWZWYNn8BgyAaK/6yFJEowxCY0RVFirRyWP63hMRuKlkSEd9qlvbWXg==} + lightningcss-android-arm64@1.32.0: resolution: {integrity: sha512-YK7/ClTt4kAK0vo6w3X+Pnm0D2cf2vPHbhOXdoNti1Ga0al1P4TBZhwjATvjNwLEBCnKvjJc2jQgHXH0NEwlAg==} engines: {node: '>= 12.0.0'} @@ -3786,6 +3804,10 @@ packages: resolution: {integrity: sha512-kiGUalWN+rgBJ/1OHZsBtU4rXZOfj/7rKQxULKlIzwzQSvMJUUNgPwJEEh7gU6xEVxC0ahoOBvN2YI8GH6FNgA==} engines: {node: '>=10.12.0'} + validator@13.15.35: + resolution: {integrity: sha512-TQ5pAGhd5whStmqWvYF4OjQROlmv9SMFVt37qoCBdqRffuuklWYQlCNnEs2ZaIBD1kZRNnikiZOS1eqgkar0iw==} + engines: {node: '>= 0.10'} + vary@1.1.2: resolution: {integrity: sha512-BNGbWLfd0eUPabhkXUVm0j8uuvREyTh5ovRa/dyow/BqAbZJyC+5fU+IzQOzmAKzYqYRAISoRhdQr3eIZ/PXqg==} engines: {node: '>= 0.8'} @@ -5104,7 +5126,7 @@ snapshots: - uglify-js - webpack-cli - '@nestjs/common@11.1.18(reflect-metadata@0.2.2)(rxjs@7.8.2)': + '@nestjs/common@11.1.18(class-transformer@0.5.1)(class-validator@0.15.1)(reflect-metadata@0.2.2)(rxjs@7.8.2)': dependencies: file-type: 21.3.4 iterare: 1.2.1 @@ -5113,20 +5135,23 @@ snapshots: rxjs: 7.8.2 tslib: 2.8.1 uid: 2.0.2 + optionalDependencies: + class-transformer: 0.5.1 + class-validator: 0.15.1 transitivePeerDependencies: - supports-color - '@nestjs/config@4.0.4(@nestjs/common@11.1.18(reflect-metadata@0.2.2)(rxjs@7.8.2))(rxjs@7.8.2)': + '@nestjs/config@4.0.4(@nestjs/common@11.1.18(class-transformer@0.5.1)(class-validator@0.15.1)(reflect-metadata@0.2.2)(rxjs@7.8.2))(rxjs@7.8.2)': dependencies: - '@nestjs/common': 11.1.18(reflect-metadata@0.2.2)(rxjs@7.8.2) + '@nestjs/common': 11.1.18(class-transformer@0.5.1)(class-validator@0.15.1)(reflect-metadata@0.2.2)(rxjs@7.8.2) dotenv: 17.4.1 dotenv-expand: 12.0.3 lodash: 4.18.1 rxjs: 7.8.2 - '@nestjs/core@11.1.18(@nestjs/common@11.1.18(reflect-metadata@0.2.2)(rxjs@7.8.2))(@nestjs/platform-express@11.1.18)(reflect-metadata@0.2.2)(rxjs@7.8.2)': + '@nestjs/core@11.1.18(@nestjs/common@11.1.18(class-transformer@0.5.1)(class-validator@0.15.1)(reflect-metadata@0.2.2)(rxjs@7.8.2))(@nestjs/platform-express@11.1.18)(reflect-metadata@0.2.2)(rxjs@7.8.2)': dependencies: - '@nestjs/common': 11.1.18(reflect-metadata@0.2.2)(rxjs@7.8.2) + '@nestjs/common': 11.1.18(class-transformer@0.5.1)(class-validator@0.15.1)(reflect-metadata@0.2.2)(rxjs@7.8.2) '@nuxt/opencollective': 0.4.1 fast-safe-stringify: 2.1.1 iterare: 1.2.1 @@ -5136,17 +5161,20 @@ snapshots: tslib: 2.8.1 uid: 2.0.2 optionalDependencies: - '@nestjs/platform-express': 11.1.18(@nestjs/common@11.1.18(reflect-metadata@0.2.2)(rxjs@7.8.2))(@nestjs/core@11.1.18) + '@nestjs/platform-express': 11.1.18(@nestjs/common@11.1.18(class-transformer@0.5.1)(class-validator@0.15.1)(reflect-metadata@0.2.2)(rxjs@7.8.2))(@nestjs/core@11.1.18) - '@nestjs/mapped-types@2.1.1(@nestjs/common@11.1.18(reflect-metadata@0.2.2)(rxjs@7.8.2))(reflect-metadata@0.2.2)': + '@nestjs/mapped-types@2.1.1(@nestjs/common@11.1.18(class-transformer@0.5.1)(class-validator@0.15.1)(reflect-metadata@0.2.2)(rxjs@7.8.2))(class-transformer@0.5.1)(class-validator@0.15.1)(reflect-metadata@0.2.2)': dependencies: - '@nestjs/common': 11.1.18(reflect-metadata@0.2.2)(rxjs@7.8.2) + '@nestjs/common': 11.1.18(class-transformer@0.5.1)(class-validator@0.15.1)(reflect-metadata@0.2.2)(rxjs@7.8.2) reflect-metadata: 0.2.2 + optionalDependencies: + class-transformer: 0.5.1 + class-validator: 0.15.1 - '@nestjs/platform-express@11.1.18(@nestjs/common@11.1.18(reflect-metadata@0.2.2)(rxjs@7.8.2))(@nestjs/core@11.1.18)': + '@nestjs/platform-express@11.1.18(@nestjs/common@11.1.18(class-transformer@0.5.1)(class-validator@0.15.1)(reflect-metadata@0.2.2)(rxjs@7.8.2))(@nestjs/core@11.1.18)': dependencies: - '@nestjs/common': 11.1.18(reflect-metadata@0.2.2)(rxjs@7.8.2) - '@nestjs/core': 11.1.18(@nestjs/common@11.1.18(reflect-metadata@0.2.2)(rxjs@7.8.2))(@nestjs/platform-express@11.1.18)(reflect-metadata@0.2.2)(rxjs@7.8.2) + '@nestjs/common': 11.1.18(class-transformer@0.5.1)(class-validator@0.15.1)(reflect-metadata@0.2.2)(rxjs@7.8.2) + '@nestjs/core': 11.1.18(@nestjs/common@11.1.18(class-transformer@0.5.1)(class-validator@0.15.1)(reflect-metadata@0.2.2)(rxjs@7.8.2))(@nestjs/platform-express@11.1.18)(reflect-metadata@0.2.2)(rxjs@7.8.2) cors: 2.8.6 express: 5.2.1 multer: 2.1.1 @@ -5166,25 +5194,28 @@ snapshots: transitivePeerDependencies: - chokidar - '@nestjs/swagger@11.2.7(@nestjs/common@11.1.18(reflect-metadata@0.2.2)(rxjs@7.8.2))(@nestjs/core@11.1.18)(reflect-metadata@0.2.2)': + '@nestjs/swagger@11.2.7(@nestjs/common@11.1.18(class-transformer@0.5.1)(class-validator@0.15.1)(reflect-metadata@0.2.2)(rxjs@7.8.2))(@nestjs/core@11.1.18)(class-transformer@0.5.1)(class-validator@0.15.1)(reflect-metadata@0.2.2)': dependencies: '@microsoft/tsdoc': 0.16.0 - '@nestjs/common': 11.1.18(reflect-metadata@0.2.2)(rxjs@7.8.2) - '@nestjs/core': 11.1.18(@nestjs/common@11.1.18(reflect-metadata@0.2.2)(rxjs@7.8.2))(@nestjs/platform-express@11.1.18)(reflect-metadata@0.2.2)(rxjs@7.8.2) - '@nestjs/mapped-types': 2.1.1(@nestjs/common@11.1.18(reflect-metadata@0.2.2)(rxjs@7.8.2))(reflect-metadata@0.2.2) + '@nestjs/common': 11.1.18(class-transformer@0.5.1)(class-validator@0.15.1)(reflect-metadata@0.2.2)(rxjs@7.8.2) + '@nestjs/core': 11.1.18(@nestjs/common@11.1.18(class-transformer@0.5.1)(class-validator@0.15.1)(reflect-metadata@0.2.2)(rxjs@7.8.2))(@nestjs/platform-express@11.1.18)(reflect-metadata@0.2.2)(rxjs@7.8.2) + '@nestjs/mapped-types': 2.1.1(@nestjs/common@11.1.18(class-transformer@0.5.1)(class-validator@0.15.1)(reflect-metadata@0.2.2)(rxjs@7.8.2))(class-transformer@0.5.1)(class-validator@0.15.1)(reflect-metadata@0.2.2) js-yaml: 4.1.1 lodash: 4.18.1 path-to-regexp: 8.4.2 reflect-metadata: 0.2.2 swagger-ui-dist: 5.32.2 + optionalDependencies: + class-transformer: 0.5.1 + class-validator: 0.15.1 - '@nestjs/testing@11.1.18(@nestjs/common@11.1.18(reflect-metadata@0.2.2)(rxjs@7.8.2))(@nestjs/core@11.1.18)(@nestjs/platform-express@11.1.18)': + '@nestjs/testing@11.1.18(@nestjs/common@11.1.18(class-transformer@0.5.1)(class-validator@0.15.1)(reflect-metadata@0.2.2)(rxjs@7.8.2))(@nestjs/core@11.1.18)(@nestjs/platform-express@11.1.18)': dependencies: - '@nestjs/common': 11.1.18(reflect-metadata@0.2.2)(rxjs@7.8.2) - '@nestjs/core': 11.1.18(@nestjs/common@11.1.18(reflect-metadata@0.2.2)(rxjs@7.8.2))(@nestjs/platform-express@11.1.18)(reflect-metadata@0.2.2)(rxjs@7.8.2) + '@nestjs/common': 11.1.18(class-transformer@0.5.1)(class-validator@0.15.1)(reflect-metadata@0.2.2)(rxjs@7.8.2) + '@nestjs/core': 11.1.18(@nestjs/common@11.1.18(class-transformer@0.5.1)(class-validator@0.15.1)(reflect-metadata@0.2.2)(rxjs@7.8.2))(@nestjs/platform-express@11.1.18)(reflect-metadata@0.2.2)(rxjs@7.8.2) tslib: 2.8.1 optionalDependencies: - '@nestjs/platform-express': 11.1.18(@nestjs/common@11.1.18(reflect-metadata@0.2.2)(rxjs@7.8.2))(@nestjs/core@11.1.18) + '@nestjs/platform-express': 11.1.18(@nestjs/common@11.1.18(class-transformer@0.5.1)(class-validator@0.15.1)(reflect-metadata@0.2.2)(rxjs@7.8.2))(@nestjs/core@11.1.18) '@noble/hashes@1.8.0': {} @@ -5745,6 +5776,8 @@ snapshots: '@types/methods': 1.1.4 '@types/superagent': 8.1.9 + '@types/validator@13.15.10': {} + '@types/webidl-conversions@7.0.3': {} '@types/whatwg-url@13.0.0': @@ -6339,6 +6372,14 @@ snapshots: cjs-module-lexer@2.2.0: {} + class-transformer@0.5.1: {} + + class-validator@0.15.1: + dependencies: + '@types/validator': 13.15.10 + libphonenumber-js: 1.12.42 + validator: 13.15.35 + cli-cursor@3.1.0: dependencies: restore-cursor: 3.1.0 @@ -7390,6 +7431,8 @@ snapshots: prelude-ls: 1.2.1 type-check: 0.4.0 + libphonenumber-js@1.12.42: {} + lightningcss-android-arm64@1.32.0: optional: true @@ -8301,6 +8344,8 @@ snapshots: '@types/istanbul-lib-coverage': 2.0.6 convert-source-map: 2.0.0 + validator@13.15.35: {} + vary@1.1.2: {} vite@8.0.8(@types/node@24.12.2)(jiti@2.6.1)(terser@5.46.1):