Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(modules/users): add ParseUUIDPipe to Param id decorators #154

Merged
merged 1 commit into from
Jan 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
// }
}
Loading