Skip to content

Commit

Permalink
implemented code suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
rajdip-b committed Mar 11, 2024
1 parent 1eef0d2 commit ec0b3ec
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 14 deletions.
3 changes: 3 additions & 0 deletions apps/api/src/common/static.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export const invalidAuthenticationResponse = {
description: 'Invalid authentication header or API key'
}
2 changes: 1 addition & 1 deletion apps/api/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ async function initializeNestApp() {
.setTitle('keyshade')
.setDescription('The keyshade API description')
.setVersion('1.0')
.addBearerAuth()
.addBearerAuth({ type: 'http', scheme: 'bearer', bearerFormat: 'JWT' })
.addSecurity('api_key', {
type: 'apiKey',
in: 'header',
Expand Down
17 changes: 5 additions & 12 deletions apps/api/src/user/controller/user.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,13 @@ import {
ApiNoContentResponse,
ApiOkResponse,
ApiOperation,
ApiResponse,
ApiSecurity,
ApiTags
} from '@nestjs/swagger'
import { BypassOnboarding } from '../../decorators/bypass-onboarding.decorator'
import { RequiredApiKeyAuthorities } from '../../decorators/required-api-key-authorities.decorator'
import { ForbidApiKey } from '../../decorators/forbid-api-key.decorator'
import { invalidAuthenticationResponse } from '../../common/static'

const userSchema = {
type: 'object',
Expand Down Expand Up @@ -63,9 +63,7 @@ export class UserController {
description: 'User details',
schema: userSchema
})
@ApiForbiddenResponse({
description: 'Invalid authentication token or API key'
})
@ApiForbiddenResponse(invalidAuthenticationResponse)
async getCurrentUser(@CurrentUser() user: User) {
return this.userService.getSelf(user)
}
Expand All @@ -82,9 +80,7 @@ export class UserController {
description: 'Updated user details',
schema: userSchema
})
@ApiForbiddenResponse({
description: 'Invalid authentication token or API key'
})
@ApiForbiddenResponse(invalidAuthenticationResponse)
async updateSelf(@CurrentUser() user: User, @Body() dto: UpdateUserDto) {
return await this.userService.updateSelf(user, dto)
}
Expand All @@ -98,11 +94,8 @@ export class UserController {
description:
'This endpoint deletes the details of the currently logged in user'
})
@ApiForbiddenResponse({
description: 'Invalid authentication token'
})
@ApiResponse({
status: 204,
@ApiForbiddenResponse(invalidAuthenticationResponse)
@ApiNoContentResponse({
description: 'User deleted successfully'
})
async deleteSelf(@CurrentUser() user: User) {
Expand Down
3 changes: 2 additions & 1 deletion apps/api/src/user/dto/create.user/create.user.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ApiProperty } from '@nestjs/swagger'
import { IsBoolean, IsOptional, IsString } from 'class-validator'
import { IsBoolean, IsEmail, IsOptional, IsString } from 'class-validator'

export class CreateUserDto {
@IsString()
Expand All @@ -15,6 +15,7 @@ export class CreateUserDto {
name: string

@IsString()
@IsEmail()
@ApiProperty({
name: 'email',
description: 'Email of the user',
Expand Down

0 comments on commit ec0b3ec

Please sign in to comment.