Skip to content

Commit

Permalink
feat(modules/users/controllers): add api auth bearer token
Browse files Browse the repository at this point in the history
  • Loading branch information
Mnigos committed Dec 23, 2023
1 parent 9bc2492 commit eee30e9
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 8 deletions.
2 changes: 1 addition & 1 deletion .eslintrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
20 changes: 15 additions & 5 deletions src/modules/users/users-profile.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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 })

Expand Down Expand Up @@ -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 })

Expand Down Expand Up @@ -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 })

Expand Down Expand Up @@ -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 })

Expand Down Expand Up @@ -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))
Expand Down
13 changes: 11 additions & 2 deletions src/modules/users/users.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {}

Expand All @@ -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)
Expand Down Expand Up @@ -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))
Expand Down

0 comments on commit eee30e9

Please sign in to comment.