@nestjs/swagger#ApiNotFoundResponse TypeScript Examples
The following examples show how to use
@nestjs/swagger#ApiNotFoundResponse.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: users.controller.ts From nest-js-boilerplate with MIT License | 8 votes |
@ApiOkResponse({
schema: {
type: 'object',
properties: {
data: {
$ref: getSchemaPath(User),
},
},
},
description: '200. Success. Returns a user',
})
@ApiNotFoundResponse({
description: '404. NotFoundException. User was not found',
})
@ApiUnauthorizedResponse({
schema: {
type: 'object',
example: {
message: 'string',
},
},
description: '401. UnauthorizedException.',
})
@ApiParam({ name: 'id', type: String })
@Get(':id')
@Serialize(UserResponseDto)
@Auth()
async getById(
@Param('id', ParseObjectIdPipe) id: Types.ObjectId,
): Promise<User> {
const foundUser = await this.usersService.getVerifiedUserById(id);
if (!foundUser) {
throw new NotFoundException('The user does not exist');
}
return foundUser;
}
Example #2
Source File: app.controller.ts From nestjs-starter with MIT License | 6 votes |
/**
* Login user authentication
* @param dto User Form
* @example /auth/login
*/
@ApiOperation({ summary: 'Login user authentication', description: 'In this way you will get the Token for Bearer authentication' })
@ApiCreatedResponse({ status: 201, description: 'Login success, you will receive the "accessToken" there' })
@ApiBadRequestResponse({ status: 400, description: 'Invalid credentials' })
@ApiForbiddenResponse({ status: 403, description: 'Account is disabled, contact with administrator' })
@ApiNotFoundResponse({ status: 404, description: 'Your account does not exist' })
@ApiUnauthorizedResponse({ status: 401, description: 'Unauthorized' })
@ApiBadGatewayResponse({ status: 502, description: 'Login user authentication' })
@ApiBody({ type: LoginDto })
@UseGuards(LocalAuthGuard)
@Post('auth/login')
async login(@Request() req, @Body() loginDto: LoginDto) {
return await this.authService.login(req.user);
}
Example #3
Source File: auth.controller.ts From nest-js-boilerplate with MIT License | 6 votes |
@ApiNoContentResponse({
description: 'No content. 204',
})
@ApiNotFoundResponse({
schema: {
type: 'object',
example: {
message: 'string',
error: 'Not Found',
},
},
description: 'User was not found',
})
@ApiInternalServerErrorResponse({
schema: {
type: 'object',
example: {
message: 'string',
details: {},
},
},
description: '500. InternalServerError',
})
@ApiBearerAuth()
@HttpCode(HttpStatus.NO_CONTENT)
@Auth(RolesEnum.admin)
@Put('verify')
async verifyUser(@Body() verifyUserDto: VerifyUserDto): Promise<User | null> {
const foundUser = await this.usersService.getUnverifiedUserByEmail(
verifyUserDto.email,
) as UserDocument;
if (!foundUser) {
throw new NotFoundException('The user does not exist');
}
return this.usersService.update(foundUser._id, { verified: true });
}
Example #4
Source File: user.controller.ts From MyAPI with MIT License | 6 votes |
@ApiOperation({ summary: 'Get the info of a user' })
@ApiNotFoundResponse({ description: 'User not found' })
@ApiForbiddenResponse({ description: 'You do not have the necessary role to perform this action' })
@ApiOkResponse({
type: User,
description: 'User information'
})
@UseGuards(RolesGuard)
@Roles(DefaultRole.Admin)
@Get(':id')
@HttpCode(HttpStatus.OK)
async findOne(
@Param('id') id: string
): Promise<User> {
const user = await this.userService.findOne(id)
if (user) {
return user
} else {
throw new NotFoundException(ERRORS.USER_NOT_FOUND)
}
}
Example #5
Source File: users.controller.ts From mamori-i-japan-api with BSD 2-Clause "Simplified" License | 6 votes |
@UsePipes(new ValidationPipe(VALIDATION_PIPE_OPTIONS))
@ApiOperation({ summary: 'Let the users themselves eliminate the positive flag' })
@ApiOkResponse({ type: NoResponseBody })
@ApiBadRequestResponse()
@ApiNotFoundResponse()
@Delete('/me/diagnosis_keys')
@HttpCode(200)
async deleteDiagnosisKeys(
@Request() req,
@Body() deleteDiagnosisKeys: DeleteDiagnosisKeysDto
): Promise<NoResponseBody> {
await this.usersService.deleteDiagnosisKeys(deleteDiagnosisKeys)
return {}
}
Example #6
Source File: users.controller.ts From mamori-i-japan-api with BSD 2-Clause "Simplified" License | 6 votes |
@UsePipes(new ValidationPipe(VALIDATION_PIPE_OPTIONS))
@ApiOperation({ summary: 'Give the user a positive flag by health-center-token' })
@ApiOkResponse({ type: NoResponseBody })
@ApiBadRequestResponse()
@ApiNotFoundResponse()
@Post('/me/health_center_tokens')
@HttpCode(200)
async createDiagnosisKeys(
@Request() req,
@Body() createDiagnosisKeys: CreateDiagnosisKeysDto
): Promise<NoResponseBody> {
await this.usersService.createDiagnosisKeys(createDiagnosisKeys)
return {}
}
Example #7
Source File: prefectures.controller.ts From mamori-i-japan-api with BSD 2-Clause "Simplified" License | 6 votes |
@UsePipes(new ValidationPipe(VALIDATION_PIPE_OPTIONS))
@ApiOperation({ summary: 'Update prefecture' })
@ApiOkResponse({ type: NoResponseBody })
@ApiNotFoundResponse()
@Patch('/prefectures/:prefectureId')
async patchMeProfile(
@Request() req,
@Param('prefectureId') prefectureId: number,
@Body() updatePrefectureRequest: UpdatePrefectureRequestDto
): Promise<NoResponseBody> {
const requestAdminUser: RequestAdminUser = req.user
updatePrefectureRequest.prefectureId = prefectureId
await this.prefecturesService.updateOnePrefecture(requestAdminUser, updatePrefectureRequest)
return {}
}
Example #8
Source File: prefectures.controller.ts From mamori-i-japan-api with BSD 2-Clause "Simplified" License | 6 votes |
@ApiOperation({ summary: 'Get prefecture by id' })
@ApiOkResponse({ type: Prefecture })
@Get('/prefectures/:prefectureId')
@ApiNotFoundResponse()
async getPrefectureById(
@Request() req,
@Param('prefectureId') prefectureId: number
): Promise<Prefecture> {
const requestAdminUser: RequestAdminUser = req.user
const prefecture = await this.prefecturesService.getOnePrefectureById(
requestAdminUser,
prefectureId
)
return prefecture
}
Example #9
Source File: admins.controller.ts From mamori-i-japan-api with BSD 2-Clause "Simplified" License | 6 votes |
@ApiOperation({ summary: 'Get admin by id' })
@ApiOkResponse({ type: NoResponseBody })
@ApiNotFoundResponse()
@Delete('/users/:userId')
async deleteAdminById(@Request() req, @Param('userId') userId: string): Promise<NoResponseBody> {
const requestAdminUser: RequestAdminUser = req.user
await this.adminsService.deleteOneAdminById(requestAdminUser, userId)
return {}
}
Example #10
Source File: admins.controller.ts From mamori-i-japan-api with BSD 2-Clause "Simplified" License | 6 votes |
@ApiOperation({ summary: 'Get admin by id' })
@ApiOkResponse({ type: Admin })
@ApiNotFoundResponse()
@Get('/users/:userId')
async getAdminById(@Request() req, @Param('userId') userId: string): Promise<Admin> {
const requestAdminUser: RequestAdminUser = req.user
const admin = await this.adminsService.getOneAdminById(requestAdminUser, userId)
return admin
}
Example #11
Source File: auth.controller.ts From nest-js-boilerplate with MIT License | 6 votes |
@ApiNoContentResponse({
description: 'No content. 204',
})
@ApiNotFoundResponse({
schema: {
type: 'object',
example: {
message: 'string',
error: 'Not Found',
},
},
description: 'User was not found',
})
@HttpCode(HttpStatus.NO_CONTENT)
@Get('verify/:token')
async verifyUser(@Param('token') token: string): Promise<{} | never> {
const { id } = await this.authService.verifyEmailVerToken(
token,
this.configService.get<string>('ACCESS_TOKEN') || '<%= config.accessTokenSecret %>',
);
const foundUser = await this.usersService.getUnverifiedUserById(id);
if (!foundUser) {
throw new NotFoundException('The user does not exist');
}
return this.usersService.update(foundUser.id, { verified: true });
}
Example #12
Source File: auth.controller.ts From nest-js-boilerplate with MIT License | 6 votes |
@ApiNoContentResponse({
description: 'No content. 204',
})
@ApiNotFoundResponse({
schema: {
type: 'object',
example: {
message: 'string',
error: 'Not Found',
},
},
description: 'User was not found',
})
@HttpCode(HttpStatus.NO_CONTENT)
@Get('verify/:token')
async verifyUser(@Param('token') token: string): Promise<User | null> {
const { id } = await this.authService.verifyEmailVerToken(
token,
this.configService.get<string>('ACCESS_TOKEN') || '<%= config.accessTokenSecret %>',
);
const foundUser = await this.usersService.getUnverifiedUserById(id) as UserDocument;
if (!foundUser) {
throw new NotFoundException('The user does not exist');
}
return this.usersService.update(foundUser._id, { verified: true });
}
Example #13
Source File: auth.controller.ts From nest-js-boilerplate with MIT License | 6 votes |
@ApiNoContentResponse({
description: 'No content. 204',
})
@ApiNotFoundResponse({
schema: {
type: 'object',
example: {
message: 'string',
error: 'Not Found',
},
},
description: 'User was not found',
})
@ApiInternalServerErrorResponse({
schema: {
type: 'object',
example: {
message: 'string',
details: {},
},
},
description: '500. InternalServerError',
})
@HttpCode(HttpStatus.NO_CONTENT)
@Put('verify')
async verifyUser(@Body() verifyUserDto: VerifyUserDto): Promise<SuccessResponseInterface | never> {
const foundUser = await this.usersService.getUnverifiedUserByEmail(
verifyUserDto.email,
);
if (!foundUser) {
throw new NotFoundException('The user does not exist');
}
return ResponseUtils.success(
'users',
await this.usersService.update(foundUser.id, { verified: true }),
);
}
Example #14
Source File: mailer-auth.controller.ts From nest-js-boilerplate with MIT License | 6 votes |
@ApiNoContentResponse({
description: 'No content. 204',
})
@ApiNotFoundResponse({
schema: {
type: 'object',
example: {
message: 'string',
error: 'Not Found',
},
},
description: 'User was not found',
})
@HttpCode(HttpStatus.NO_CONTENT)
@Get('verify/:token')
async verifyUser(@Param('token') token: string): Promise<SuccessResponseInterface | never> {
const { id } = await this.authService.verifyEmailVerToken(
token,
this.configService.get<string>('ACCESS_TOKEN') || '<%= config.accessTokenSecret %>',
);
const foundUser = await this.usersService.getUnverifiedUserById(id);
if (!foundUser) {
throw new NotFoundException('The user does not exist');
}
return ResponseUtils.success(
'users',
await this.usersService.update(foundUser.id, { verified: true }),
);
}
Example #15
Source File: auth.controller.ts From nest-js-boilerplate with MIT License | 6 votes |
@ApiNoContentResponse({
description: 'No content. 204',
})
@ApiNotFoundResponse({
schema: {
type: 'object',
example: {
message: 'string',
error: 'Not Found',
},
},
description: 'User was not found',
})
@ApiInternalServerErrorResponse({
schema: {
type: 'object',
example: {
message: 'string',
details: {},
},
},
description: '500. InternalServerError',
})
@HttpCode(HttpStatus.NO_CONTENT)
@Put('verify')
async verifyUser(@Body() verifyUserDto: VerifyUserDto): Promise<SuccessResponseInterface | never> {
const foundUser = await this.usersService.getUnverifiedUserByEmail(
verifyUserDto.email
);
if (!foundUser) {
throw new NotFoundException('The user does not exist');
}
return ResponseUtils.success(
'users',
await this.usersService.update(foundUser.id, { verified: true }),
);
}
Example #16
Source File: mailer-auth.controller.ts From nest-js-boilerplate with MIT License | 6 votes |
@ApiNoContentResponse({
description: 'No content. 204',
})
@ApiNotFoundResponse({
schema: {
type: 'object',
example: {
message: 'string',
error: 'Not Found',
},
},
description: 'User was not found',
})
@HttpCode(HttpStatus.NO_CONTENT)
@Get('verify/:token')
async verifyUser(@Param('token') token: string): Promise<SuccessResponseInterface | never> {
const { id } = await this.authService.verifyEmailVerToken(
token,
this.configService.get<string>('ACCESS_TOKEN') || '<%= config.accessTokenSecret %>',
);
const foundUser = await this.usersService.getUnverifiedUserById(id) as UserDocument;
if (!foundUser) {
throw new NotFoundException('The user does not exist');
}
return ResponseUtils.success(
'users',
await this.usersService.update(foundUser._id, { verified: true }),
);
}
Example #17
Source File: users.controller.ts From nest-js-boilerplate with MIT License | 6 votes |
@ApiOkResponse({
schema: {
type: 'object',
properties: {
data: {
$ref: getSchemaPath(UserEntity),
},
},
},
description: '200. Success. Returns a user',
})
@ApiNotFoundResponse({
description: '404. NotFoundException. User was not found',
})
@ApiUnauthorizedResponse({
schema: {
type: 'object',
example: {
message: 'string',
},
},
description: '401. UnauthorizedException.',
})
@ApiParam({ name: 'id', type: String })
@Get(':id')
@UseGuards(JwtAccessGuard)
@Serialize(UserResponseEntity)
async getById(
@Param('id', ParseIntPipe) id: number,
): Promise<UserEntity | never> {
const foundUser = await this.usersService.getVerifiedUserById(id);
if (!foundUser) {
throw new NotFoundException('The user does not exist');
}
return foundUser;
}
Example #18
Source File: users.controller.ts From nest-js-boilerplate with MIT License | 6 votes |
@ApiOkResponse({
type: UserEntity,
description: 'Returns a found user',
})
@ApiNotFoundResponse({ description: '404...' })
@Get('/profile')
@UseGuards(IsLoggedGuard)
@Serialize(UserResponseEntity)
async getById(
@RequestUser() user: UserEntity,
): Promise<UserEntity | never> {
const foundUser = await this.usersService.getVerifiedUserById(user.id);
if (!foundUser) {
throw new NotFoundException('The user does not exist');
}
return foundUser;
}
Example #19
Source File: users.controller.ts From nest-js-boilerplate with MIT License | 6 votes |
@ApiOkResponse({
schema: {
type: 'object',
properties: {
data: {
$ref: getSchemaPath(UserEntity),
},
},
},
description: '200. Success. Returns a user',
})
@ApiNotFoundResponse({
description: '404. NotFoundException. User was not found',
})
@ApiUnauthorizedResponse({
schema: {
type: 'object',
example: {
message: 'string',
},
},
description: '401. UnauthorizedException.',
})
@ApiParam({ name: 'id', type: String })
@Get(':id')
@UseGuards(JwtAccessGuard)
@Serialize(UserResponseEntity)
async getById(
@Param('id', ParseIntPipe) id: number,
): Promise<UserEntity | never> {
const foundUser = await this.usersService.getVerifiedUserById(id);
if (!foundUser) {
throw new NotFoundException('The user does not exist');
}
return foundUser;
}
Example #20
Source File: auth.controller.ts From nest-js-boilerplate with MIT License | 6 votes |
@ApiNoContentResponse({
description: 'No content. 204',
})
@ApiNotFoundResponse({
schema: {
type: 'object',
example: {
message: 'string',
error: 'Not Found',
},
},
description: 'User was not found',
})
@ApiInternalServerErrorResponse({
schema: {
type: 'object',
example: {
message: 'string',
details: {},
},
},
description: '500. InternalServerError',
})
@HttpCode(HttpStatus.NO_CONTENT)
@Put('verify')
async verifyUser(@Body() verifyUserDto: VerifyUserDto): Promise<{} | never> {
const foundUser = await this.usersService.getUnverifiedUserByEmail(
verifyUserDto.email,
);
if (!foundUser) {
throw new NotFoundException('The user does not exist');
}
return this.usersService.update(foundUser.id, { verified: true });
}
Example #21
Source File: users.controller.ts From nest-js-boilerplate with MIT License | 6 votes |
@ApiOkResponse({
type: UserResponseDto,
description: 'Returns a found user',
})
@ApiNotFoundResponse({ description: '404...' })
@Get('/profile')
@Serialize(UserResponseDto)
@UseGuards(IsLoggedGuard)
async getById(
@RequestUser() user: UserDocument,
): Promise<UserDocument | never> {
const foundUser = await this.usersService.getVerifiedUserById(user._id) as UserDocument;
if (!foundUser) {
throw new NotFoundException('The user does not exist');
}
return foundUser;
}
Example #22
Source File: users.controller.ts From nest-js-boilerplate with MIT License | 5 votes |
@ApiOkResponse({
schema: {
type: 'object',
properties: {
data: {
$ref: getSchemaPath(UserEntity),
},
},
},
description: '200. Success. Returns a user',
})
@ApiNotFoundResponse({
description: '404. NotFoundException. User was not found',
})
@ApiUnauthorizedResponse({
schema: {
type: 'object',
example: {
message: 'string',
},
},
description: '401. UnauthorizedException.',
})
@ApiParam({ name: 'id', type: String })
@Get(':id')
@UseGuards(JwtAccessGuard)
@Serialize(AllUsersResponseEntity)
async getById(
@Param('id', ParseIntPipe) id: number,
): Promise<SuccessResponseInterface> {
const foundUser = await this.usersService.getVerifiedUserById(id);
if (!foundUser) {
throw new NotFoundException('The user does not exist');
}
return ResponseUtils.success(
'users',
foundUser,
);
}
Example #23
Source File: api-response.ts From aqualink-app with MIT License | 5 votes |
ApiNestNotFoundResponse = (description: string) => {
return applyDecorators(
ApiNotFoundResponse({
schema: errorSchema(HttpStatus.NOT_FOUND),
description,
}),
);
}
Example #24
Source File: users.controller.ts From nest-js-boilerplate with MIT License | 5 votes |
@ApiOkResponse({
schema: {
type: 'object',
properties: {
data: {
$ref: getSchemaPath(User),
},
},
},
description: '200. Success. Returns a user',
})
@ApiNotFoundResponse({
description: '404. NotFoundException. User was not found',
})
@ApiUnauthorizedResponse({
schema: {
type: 'object',
example: {
message: 'string',
},
},
description: '401. UnauthorizedException.',
})
@ApiParam({ name: 'id', type: String })
@Get(':id')
@Serialize(UserResponseDto)
@Auth()
async getById(
@Param('id', ParseObjectIdPipe) id: Types.ObjectId,
): Promise<UserResponseDto> {
const foundUser = await this.usersService.getVerifiedUserById(id);
if (!foundUser) {
throw new NotFoundException('The user does not exist');
}
return ResponseUtils.success(
'users',
foundUser,
);
}
Example #25
Source File: auth.controller.ts From nest-js-boilerplate with MIT License | 5 votes |
@ApiNoContentResponse({
description: 'No content. 204',
})
@ApiNotFoundResponse({
schema: {
type: 'object',
example: {
message: 'string',
error: 'Not Found',
},
},
description: 'User was not found',
})
@ApiInternalServerErrorResponse({
schema: {
type: 'object',
example: {
message: 'string',
details: {},
},
},
description: '500. InternalServerError',
})
@ApiBearerAuth()
@HttpCode(HttpStatus.NO_CONTENT)
@Auth(RolesEnum.admin)
@Put('verify')
async verifyUser(@Body() verifyUserDto: VerifyUserDto): Promise<SuccessResponseInterface | never> {
const foundUser = await this.usersService.getUnverifiedUserByEmail(
verifyUserDto.email
) as UserDocument;
if (!foundUser) {
throw new NotFoundException('The user does not exist');
}
return ResponseUtils.success(
'users',
await this.usersService.update(foundUser._id, { verified: true }),
);
}