Skip to content

Commit

Permalink
getUserIdByUsername
Browse files Browse the repository at this point in the history
  • Loading branch information
melihgezerr committed Dec 23, 2023
1 parent 2c143f9 commit d97b585
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
8 changes: 8 additions & 0 deletions ludos/backend/src/controllers/user.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -183,4 +183,12 @@ export class UserController {
const suggestedGames = await this.userService.getSuggestedGames(req.user.id);
return suggestedGames;
}

@ApiOperation({ summary: 'Get User Id By Username' })
@ApiNotFoundResponse({ description: 'User is not found!' })
@Get('/:username')
public async getUserIdByUsername(@Param('userId') username: string) {
return await this.userService.getUserIdByUsername(username);
}

}
12 changes: 12 additions & 0 deletions ludos/backend/src/services/user.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -229,4 +229,16 @@ export class UserService {

return suggestedGamesResponse;
}

public async getUserIdByUsername(username: string): Promise<string | null> {
const user = await this.userRepository.findUserByUsername(username);

if (user) {
return user.id;
}

return null;
}


}

0 comments on commit d97b585

Please sign in to comment.