From dfaa45e64311650e69dfb6f32c974142b7613935 Mon Sep 17 00:00:00 2001 From: Alp Date: Mon, 29 Jan 2024 00:08:45 +0300 Subject: [PATCH] Add country code validation and return message --- src/controllers/leaderboard.controller.ts | 12 ++++++++++-- src/controllers/user.controller.ts | 9 +++++++-- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/src/controllers/leaderboard.controller.ts b/src/controllers/leaderboard.controller.ts index 05e4240..e604d66 100644 --- a/src/controllers/leaderboard.controller.ts +++ b/src/controllers/leaderboard.controller.ts @@ -1,4 +1,11 @@ -import { Controller, Get, Param, Req, UseGuards } from '@nestjs/common'; +import { + Controller, + Get, + Param, + ParseEnumPipe, + Req, + UseGuards, +} from '@nestjs/common'; import { ApiBearerAuth, ApiResponse, ApiTags } from '@nestjs/swagger'; import { AuthGuard } from '../services/guards'; import { IAuthorizedRequest } from '../interfaces'; @@ -8,6 +15,7 @@ import { MyRankResponseDto, TournamentLeaderboardResponseDto, } from '../dtos/leaderboard/responses'; +import { Country } from '../enums'; @ApiBearerAuth() @Controller('/api/leaderboard') @@ -48,7 +56,7 @@ export class LeaderboardController { }) @Get('/country/:countryCode') public async getCountryLeaderboard( - @Param('countryCode') countryCode: string, + @Param('countryCode', new ParseEnumPipe(Country)) countryCode: Country, ): Promise { return await this.leaderboardService.getCountryLeaderboard(countryCode); } diff --git a/src/controllers/user.controller.ts b/src/controllers/user.controller.ts index 70da351..ae62843 100644 --- a/src/controllers/user.controller.ts +++ b/src/controllers/user.controller.ts @@ -92,8 +92,13 @@ export class UserController { description: 'Internal server error, contact with backend team.', }) @Post('/complete-level') - public async claimReward(@Req() req: IAuthorizedRequest): Promise { + public async claimReward( + @Req() req: IAuthorizedRequest, + ): Promise<{ message: string }> { const user = req.user; - return await this.userService.completeLevel(user.username); + await this.userService.completeLevel(user.username); + return { + message: 'Your complete level request is successfully processed.', + }; } }