Skip to content

Commit

Permalink
feat(modules/users): add ParseUUIDPipe to Param id decorators
Browse files Browse the repository at this point in the history
  • Loading branch information
Mnigos committed Jan 16, 2024
1 parent b157072 commit fbcf66b
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 35 deletions.
1 change: 1 addition & 0 deletions .eslintrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ module.exports = {
'@typescript-eslint/no-empty-function': 'off',
'@typescript-eslint/no-floating-promises': 'off',
'@typescript-eslint/no-non-null-assertion': 'off',
'@typescript-eslint/no-unsafe-argument': 'off',
'import/order': [
'warn',
{
Expand Down
14 changes: 8 additions & 6 deletions src/modules/users/users-playback.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {
Get,
NotFoundException,
Param,
ParseUUIDPipe,
Put,
UnauthorizedException,
} from '@nestjs/common'
Expand Down Expand Up @@ -53,7 +54,10 @@ export class UsersPlaybackController {
@ApiBadRequestResponse({
description: ONE_IS_INVALID('uuid'),
})
async getPlaybackState(@Param('id') id: string, @Token() _token?: string) {
async getPlaybackState(
@Param('id', ParseUUIDPipe) id: string,
@Token() _token?: string
) {
const foundUser = await this.usersRepository.findOneBy({ id })

if (!foundUser) throw new NotFoundException(NOT_BEEN_FOUND(USER))
Expand All @@ -80,7 +84,7 @@ export class UsersPlaybackController {
description: ONE_IS_INVALID('uuid'),
})
async pausePlayback(
@Param('id') id: string,
@Param('id', ParseUUIDPipe) id: string,
@Token() accessToken: string
): Promise<Success> {
const foundUser = await this.usersRepository.findOneBy({ id })
Expand Down Expand Up @@ -118,7 +122,7 @@ export class UsersPlaybackController {
description: ONE_IS_INVALID('uuid'),
})
async resumePlayback(
@Param('id') id: string,
@Param('id', ParseUUIDPipe) id: string,
@Token() accessToken: string
): Promise<Success> {
const foundUser = await this.usersRepository.findOneBy({ id })
Expand All @@ -128,9 +132,7 @@ export class UsersPlaybackController {
const meProfile = await this.spotifyAuthService.getMeProfile(accessToken)

if (foundUser.profile.id !== meProfile.id)
throw new UnauthorizedException(
'You are not allowed to resume playback.'
)
throw new UnauthorizedException('You are not allowed to resume playback.')

const token = await this.spotifyAuthService.token({
refreshToken: foundUser.refreshToken,
Expand Down
29 changes: 0 additions & 29 deletions src/modules/users/users-profile.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -243,33 +243,4 @@ export class UsersProfileController {

return this.spotifyUsersService.getAnalysis(token)
}

// @Get('state')
// @ApiOperation({
// summary: "Getting user's playback state.",
// })
// @ApiParam({ name: 'id' })
// @ApiOkResponse({
// description: ONE_SUCCESFULLY_FOUND(USER),
// })
// @ApiNotFoundResponse({
// description: NOT_BEEN_FOUND(USER),
// })
// @ApiBadRequestResponse({
// description: ONE_IS_INVALID('uuid'),
// })
// async getState(
// @Param('id', ParseUUIDPipe) id: string,
// @Token() _token?: string
// ) {
// const foundUser = await this.usersRepository.findOneBy({ id })

// if (!foundUser) throw new NotFoundException(NOT_BEEN_FOUND(USER))

// const token = await this.spotifyAuthService.token({
// refreshToken: foundUser.refreshToken,
// })

// return this.spotifyPlayerService.getPlaybackState(token)
// }
}

0 comments on commit fbcf66b

Please sign in to comment.