From eee30e97f311d3f9c1b4ef6664de2066e6217cf3 Mon Sep 17 00:00:00 2001 From: Mnigos Date: Sat, 23 Dec 2023 08:28:56 +0100 Subject: [PATCH] feat(modules/users/controllers): add api auth bearer token --- .eslintrc.cjs | 2 +- src/modules/users/users-profile.controller.ts | 20 ++++++++++++++----- src/modules/users/users.controller.ts | 13 ++++++++++-- 3 files changed, 27 insertions(+), 8 deletions(-) diff --git a/.eslintrc.cjs b/.eslintrc.cjs index 29792c38..18c90205 100644 --- a/.eslintrc.cjs +++ b/.eslintrc.cjs @@ -69,7 +69,7 @@ module.exports = { 'prefer-const': 'warn', '@typescript-eslint/no-unused-vars': [ 'error', - { ignoreRestSiblings: true }, + { ignoreRestSiblings: true, argsIgnorePattern: '^_' }, ], '@typescript-eslint/interface-name-prefix': 'off', '@typescript-eslint/explicit-function-return-type': 'off', diff --git a/src/modules/users/users-profile.controller.ts b/src/modules/users/users-profile.controller.ts index b9ad011e..892006a0 100644 --- a/src/modules/users/users-profile.controller.ts +++ b/src/modules/users/users-profile.controller.ts @@ -32,9 +32,12 @@ import { NOT_BEEN_FOUND, ONE_IS_INVALID, } from '@common/constants' +import { ApiAuth, Token } from '@modules/auth/decorators' +import { AuthenticationType } from '@modules/auth/enums' @Controller('users/:id/profile') @ApiTags('users/{id}/profile') +@ApiAuth(AuthenticationType.ACCESS_TOKEN) export class UsersProfileController { constructor( private readonly usersRepository: UsersRepository, @@ -60,7 +63,8 @@ export class UsersProfileController { }) async getLastTracks( @Param('id', ParseUUIDPipe) id: string, - @Query() { limit, before, after }: LastItemQuery + @Query() { limit, before, after }: LastItemQuery, + @Token() _token?: string ) { const foundUser = await this.usersRepository.findOneBy({ id }) @@ -90,7 +94,8 @@ export class UsersProfileController { }) async getTopArtists( @Param('id', ParseUUIDPipe) id: string, - @Query() { limit, timeRange, offset }: TopItemQuery + @Query() { limit, timeRange, offset }: TopItemQuery, + @Token() _token?: string ) { const foundUser = await this.usersRepository.findOneBy({ id }) @@ -125,7 +130,8 @@ export class UsersProfileController { }) async getTopTracks( @Param('id', ParseUUIDPipe) id: string, - @Query() { limit, timeRange, offset }: TopItemQuery + @Query() { limit, timeRange, offset }: TopItemQuery, + @Token() _token?: string ) { const foundUser = await this.usersRepository.findOneBy({ id }) @@ -160,7 +166,8 @@ export class UsersProfileController { }) async getTopGenres( @Param('id', ParseUUIDPipe) id: string, - @Query() { limit, timeRange, offset }: TopItemQuery + @Query() { limit, timeRange, offset }: TopItemQuery, + @Token() _token?: string ) { const foundUser = await this.usersRepository.findOneBy({ id }) @@ -192,7 +199,10 @@ export class UsersProfileController { @ApiBadRequestResponse({ description: ONE_IS_INVALID('uuid'), }) - async getAnalysis(@Param('id', ParseUUIDPipe) id: string) { + async getAnalysis( + @Param('id', ParseUUIDPipe) id: string, + @Token() _token?: string + ) { const foundUser = await this.usersRepository.findOneBy({ id }) if (!foundUser) throw new NotFoundException(NOT_BEEN_FOUND(USER)) diff --git a/src/modules/users/users.controller.ts b/src/modules/users/users.controller.ts index d3db6cc3..68c9884a 100644 --- a/src/modules/users/users.controller.ts +++ b/src/modules/users/users.controller.ts @@ -28,12 +28,15 @@ import { ONE_IS_INVALID, ONE_SUCCESFULLY_FOUND, } from '@common/constants' +import { AuthenticationType } from '@modules/auth/enums' +import { ApiAuth, Token } from '@modules/auth/decorators' export const USER = 'user' export const USERS = 'users' @Controller(USERS) @ApiTags(USERS) +@ApiAuth(AuthenticationType.ACCESS_TOKEN) export class UsersController { constructor(private readonly usersRepository: UsersRepository) {} @@ -49,7 +52,10 @@ export class UsersController { @ApiNoContentResponse({ description: NOT_BEEN_FOUND(USER), }) - async getAll(@Query('displayName') displayName?: string) { + async getAll( + @Query('displayName') displayName?: string, + @Token() _token?: string + ) { if (displayName) { const foundUser = await this.usersRepository.findOneByDisplayName(displayName) @@ -78,7 +84,10 @@ export class UsersController { @ApiBadRequestResponse({ description: ONE_IS_INVALID('uuid'), }) - async getOneById(@Param('id', ParseUUIDPipe) id: string) { + async getOneById( + @Param('id', ParseUUIDPipe) id: string, + @Token() _token?: string + ) { const foundUser = await this.usersRepository.findOneBy({ id }) if (!foundUser) throw new NotFoundException(NOT_BEEN_FOUND(USER))