Skip to content

Commit

Permalink
Add country code validation and return message
Browse files Browse the repository at this point in the history
  • Loading branch information
Alputer committed Jan 28, 2024
1 parent 3964503 commit dfaa45e
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
12 changes: 10 additions & 2 deletions src/controllers/leaderboard.controller.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -8,6 +15,7 @@ import {
MyRankResponseDto,
TournamentLeaderboardResponseDto,
} from '../dtos/leaderboard/responses';
import { Country } from '../enums';

@ApiBearerAuth()
@Controller('/api/leaderboard')
Expand Down Expand Up @@ -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<any> {
return await this.leaderboardService.getCountryLeaderboard(countryCode);
}
Expand Down
9 changes: 7 additions & 2 deletions src/controllers/user.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<void> {
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.',
};
}
}

0 comments on commit dfaa45e

Please sign in to comment.