@nestjs/common#ParseIntPipe TypeScript Examples
The following examples show how to use
@nestjs/common#ParseIntPipe.
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: user.controller.ts From nestjs-api-example with MIT License | 9 votes |
@Get(':id')
@ApiOperation({ summary: '유저 정보 조회 API' })
@ApiOkResponse({
description: 'Id가 일치하는 유저 정보를 조회한다.',
type: UserResponseDto,
})
async findOne(
@Param('id', new ParseIntPipe()) id: number,
@Res() res: Response,
) {
const responseDto = await this.userService.findById(id);
return res.status(HttpStatus.OK).json(instanceToPlain(responseDto));
}
Example #2
Source File: sites.controller.ts From aqualink-app with MIT License | 6 votes |
@ApiBearerAuth()
@ApiNestNotFoundResponse('No site was found with the specified id')
@ApiNestBadRequestResponse(
'Site has no spotter or start date is larger than end date',
)
@ApiOperation({ summary: "Adds exclusion dates to spotter's data" })
@ApiParam({ name: 'siteId', example: 1 })
@UseGuards(IsSiteAdminGuard)
@Post(':siteId/exclusion_dates')
addExclusionDates(
@Param('siteId', ParseIntPipe) id: number,
@Body() excludeSpotterDatesDto: ExcludeSpotterDatesDto,
): Promise<void> {
return this.sitesService.addExclusionDates(id, excludeSpotterDatesDto);
}
Example #3
Source File: role.controller.ts From MyAPI with MIT License | 6 votes |
@ApiOperation({ summary: 'Delete a role' })
@ApiOkResponse({ description: 'Role deleted' })
@ApiBadRequestResponse({ description: 'The role could not be deleted' })
@ApiForbiddenResponse({ description: 'You do not have the necessary role to perform this action' })
@Delete(':id')
@HttpCode(HttpStatus.OK)
async delete(
@Param('id', ParseIntPipe) id: number
): Promise<void> {
if (id === DefaultRole.User) {
throw new BadRequestException(ERRORS.ROLE_USER_DELETION)
} else if (id === DefaultRole.Admin) {
throw new BadRequestException(ERRORS.ROLE_ADMIN_DELETION)
}
try {
await this.roleService.delete(id)
} catch (error) {
this.logger.error(error.message, 'DELETE_ROLE')
throw new BadRequestException(error.message)
}
}
Example #4
Source File: user.controller.ts From nestjs-api-example with MIT License | 6 votes |
@Put(':id')
@ApiOperation({ summary: '유저 정보 수정 API' })
@ApiOkResponse({
description: 'Id가 일치하는 유저 정보를 수정한다.',
type: User,
})
async update(
@Param('id', new ParseIntPipe()) id: number,
@Body() requestDto: UserUpdateRequestDto,
@Res() res: Response,
) {
const updatedUser = await this.userService.updateUser(id, requestDto);
return res.status(HttpStatus.OK).json(updatedUser);
}
Example #5
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 #6
Source File: documentType.controller.ts From MyAPI with MIT License | 6 votes |
@ApiBearerAuth()
@ApiOperation({ summary: 'Delete document type' })
@ApiOkResponse({ description: 'The document type has been deleted successfully' })
@ApiBadRequestResponse({ description: 'The document type could not be deleted' })
@ApiForbiddenResponse({ description: 'You do not have the necessary role to perform this action' })
@UseGuards(AuthGuard(), RolesGuard)
@Roles(DefaultRole.Admin)
@Delete(':id')
@HttpCode(HttpStatus.OK)
async deleteDocumentType(
@Param('id', ParseIntPipe) id: number
): Promise<void> {
const usersWithDocumentType = await this.userService.countByDocumentTypeId(id)
if (usersWithDocumentType > 0) {
throw new BadRequestException(ERRORS.USER_HAS_DOCUMENT_TYPE)
}
try {
await this.documentTypeService.delete(id)
} catch (error) {
switch (error.code) {
default:
this.logger.error(error.message, 'DELETE_DOCUMENT_TYPE')
throw new BadRequestException(error.message)
}
}
}
Example #7
Source File: quiz.controller.ts From nest-js-quiz-manager with MIT License | 6 votes |
@Get('/')
@ApiPaginatedResponse({ model: Quiz, description: 'List of quizzes' })
async getAllQuiz(
@Query('page', new DefaultValuePipe(1), ParseIntPipe) page: number = 1,
@Query('limit', new DefaultValuePipe(10), ParseIntPipe) limit: number = 1,
): Promise<Pagination<Quiz>> {
const options: IPaginationOptions = {
limit,
page,
};
return await this.quizService.paginate(options);
}
Example #8
Source File: collections.controller.ts From aqualink-app with MIT License | 6 votes |
@ApiOperation({
summary: 'Fetch detailed data from specified public collection',
})
@ApiNestNotFoundResponse('No collection was found with the specified id')
@ApiParam({ name: 'collectionId', example: 1 })
@Public()
@Get('public/:collectionId')
findOnePublic(@Param('collectionId', ParseIntPipe) collectionId: number) {
return this.collectionsService.findOne(collectionId, true);
}
Example #9
Source File: post.controller.ts From nestjs-rest-sample with GNU General Public License v3.0 | 5 votes |
@Get('')
getAllPosts(
@Query('q') keyword?: string,
@Query('limit', new DefaultValuePipe(10), ParseIntPipe) limit?: number,
@Query('skip', new DefaultValuePipe(0), ParseIntPipe) skip?: number,
): Observable<BlogPost[]> {
return this.postService.findAll(keyword, skip, limit);
}
Example #10
Source File: user.controller.ts From MyAPI with MIT License | 5 votes |
@ApiOperation({ summary: 'Get all users' })
@ApiOkResponse({ description: 'List of users', type: User, isArray: true })
@ApiInternalServerErrorResponse({ description: 'Internal Server Error' })
@ApiForbiddenResponse({ description: 'You do not have the necessary role to perform this action' })
@ApiQuery({
name: 'search',
required: false,
type: String
})
@ApiQuery({
name: 'offset',
required: false,
type: Number
})
@ApiQuery({
name: 'limit',
required: false,
type: Number
})
@UseGuards(RolesGuard)
@Roles(DefaultRole.Admin)
@Get()
@HttpCode(HttpStatus.OK)
async findAll(
@Query(
'search',
new DefaultValuePipe('')
) search: string,
@Query(
'offset',
new DefaultValuePipe(0),
ParseIntPipe
) offset: number,
@Query(
'limit',
new DefaultValuePipe(10),
ParseIntPipe
) limit: number
): Promise<Array<User>> {
const users = await this.userService.findByRoleIds(
[DefaultRole.Admin, DefaultRole.User],
search,
offset,
limit
)
return users as Array<User>
}
Example #11
Source File: cat.resolver.ts From nestjs-mercurius with MIT License | 5 votes |
@Query(() => Cat, { nullable: true })
cat(@Args({ name: 'id', type: () => ID }, ParseIntPipe) id: number) {
return this.catService.cat(id);
}
Example #12
Source File: surveys.controller.ts From aqualink-app with MIT License | 5 votes |
@ApiOperation({ summary: "Returns all site's survey" })
@ApiParam({ name: 'siteId', example: 1 })
@Public()
@Get()
find(@Param('siteId', ParseIntPipe) siteId: number): Promise<Survey[]> {
return this.surveyService.find(siteId);
}
Example #13
Source File: quiz.controller.ts From nest-js-quiz-manager with MIT License | 5 votes |
@Get('/:id')
@ApiOkResponse({ description: 'Get a quiz by id', type: Quiz })
async getQuizById(@Param('id', ParseIntPipe) id: number): Promise<Quiz> {
return await this.quizService.getQuizById(id);
}
Example #14
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 #15
Source File: cats.resolvers.ts From nestjs-mercurius with MIT License | 5 votes |
@Query('cat')
async findOneById(
@Args('id', ParseIntPipe)
id: number,
): Promise<Cat> {
return await this.catsService.findOneById(id);
}