@nestjs/common#Param TypeScript Examples
The following examples show how to use
@nestjs/common#Param.
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 | 7 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: card.controller.ts From 42_checkIn with GNU General Public License v3.0 | 6 votes |
@UseGuards(JwtAuthGuard)
@Post('create/:type')
async createCard(
@Req() req: any,
@Query('start') start: number,
@Query('end') end: number,
@Param('type') type: number,
) {
return await this.cardServcie.createCard(req.user._id, start, end, type);
}
Example #3
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 #4
Source File: posts.controller.ts From NestJs-youtube with MIT License | 6 votes |
@Override('updateOneBase')
@UseGuards(JwtAuthGuard, IsOwnerGuard)
updateOne(
@Request() req: Express.Request,
@Param('id') id: number,
@ParsedRequest() pReq: CrudRequest,
@ParsedBody() body: Partial<PostEntity>) {
console.log({ user: (req as any).user, update: true, id });
const obj = { ...body, user_id: (req as any).user.id };
return this.base.updateOneBase(pReq, obj);
}
Example #5
Source File: users.controller.ts From nest-js-boilerplate with MIT License | 6 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 #6
Source File: attribution.ts From barista with Apache License 2.0 | 6 votes |
@Get('/byScanId/:id')
@ApiResponse({ status: 200, type: [ProjectDistinctLicenseAttributionDto] })
async getAttributions(@Param('id') id: number): Promise<ProjectDistinctLicenseAttributionDto[]> {
if (id) {
const scan = await this.service.findOne(id);
if (scan) {
return this.service.distinctLicenseAttributions(scan.id);
}
}
}
Example #7
Source File: file.controller.ts From whispr with MIT License | 6 votes |
@Get('*')
async getFile(@Param('*') key: string, @Res() response: FastifyReply): Promise<void> {
try {
const file = await this.fileService.getFile(key);
response.type(file.ContentType);
response.send(file.Body);
} catch (error) {
Logger.error(error);
response.status(404);
response.send();
}
}
Example #8
Source File: account.controller.ts From uniauth-backend with MIT License | 6 votes |
@Get('/password/reset/:token')
async showPasswordResetPage(@Res() res: Response, @Param('token') token: string) {
try {
this.mailerService.checkPasswordResetToken(token);
return res.render('password/reset', { project_name: appData.Name });
} catch (e) {
return res.render('error', e.response);
}
}
Example #9
Source File: LocalBlueprintController.ts From rewind with MIT License | 6 votes |
@Get(":md5hash/folder/:file")
async redirectToFolder(@Res() res: Response, @Param("md5hash") md5hash: string, @Param("file") file: string) {
const blueprintMetaData = await this.blueprint(md5hash);
const { folderName } = blueprintMetaData;
// We need to encode the URI components for cases such as:
// "E:\osu!\Songs\1192060 Camellia - #1f1e33\Camellia - #1f1e33 (Realazy) [Amethyst Storm].osu"
// The two `#` characters need to be encoded to `%23` in both cases.
const url = `/static/songs/${encodeURIComponent(folderName)}/${encodeURIComponent(file)}`;
res.redirect(url);
}
Example #10
Source File: build.controller.ts From amplication with Apache License 2.0 | 6 votes |
@Get(`/:id.zip`)
@UseInterceptors(MorganInterceptor('combined'))
async getGeneratedAppArchive(@Param('id') id: string, @Res() res: Response) {
let stream: NodeJS.ReadableStream;
try {
stream = await this.buildService.download({ where: { id } });
} catch (error) {
if (error instanceof StepNotCompleteError) {
throw new BadRequestException(error.message);
}
if (
error instanceof BuildNotFoundError ||
error instanceof BuildResultNotFound ||
error instanceof StepNotFoundError
) {
throw new NotFoundException(error.message);
}
throw error;
}
res.set({
// eslint-disable-next-line @typescript-eslint/naming-convention
'Content-Type': ZIP_MIME,
// eslint-disable-next-line @typescript-eslint/naming-convention
'Content-Disposition': `attachment; filename="${id}.zip"`
});
stream.pipe(res);
}
Example #11
Source File: TodoListEventsController.ts From remix-hexagonal-architecture with MIT License | 6 votes |
@Sse("/:todoListId")
async getEvents(@Param("todoListId") todoListId: string) {
const currentUser = await this.authenticator.currentUser();
const heartbeat$ = interval(30_000).pipe(
map(() => ({ type: "heartbeat", data: "_" }))
);
const updates$ = this.todoListEvents.events.pipe(
filter(
(event) =>
event.todoListId === todoListId &&
event.sessionId !== currentUser.sessionId
),
map((event) => ({ type: "update", data: event.type } as MessageEvent))
);
return merge(heartbeat$, updates$);
}
Example #12
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 #13
Source File: organizations.controller.ts From nestjs-rest-microservices with MIT License | 6 votes |
@Post(':name/comments')
@Header('Content-Type', 'application/json')
async createOrganizationComment(@Param('name') name: string, @Body() comment: CommentDto): Promise<Comment> {
this.logger.info('OrganizationController#createOrganizationComment.call', name)
const organization: Organization = await this.organizationsService
.findByName({
name
})
.toPromise()
if (!organization) throw new NotFoundException('NOT_FOUND', 'Organization not found.')
const result: Comment = await this.commentsService
.create({
...comment,
organization: organization.id
})
.toPromise()
this.logger.info('OrganizationController#createOrganizationComment.result', result)
return result
}
Example #14
Source File: mentor.controller.ts From codeclannigeria-backend with MIT License | 6 votes |
@Post('grade/:submissionId')
@HttpCode(HttpStatus.OK)
@ApiResponse({ status: HttpStatus.OK })
@UseGuards(JwtAuthGuard, RolesGuard)
@Roles(UserRole.MENTOR)
@ApiBearerAuth()
@ApiResponse({ status: HttpStatus.BAD_REQUEST, type: ApiException })
async gradeTask(
@Param('submissionId') submissionId: string,
@Body() input: GradeSubmissionDto,
@Req() req: Request
): Promise<void> {
const mentorId = req.user['userId'];
const submission = await this.SubmissionModel.findOne({
_id: submissionId,
mentor: mentorId
});
if (!submission)
throw new NotFoundException(
`Submission with the id ${submissionId} not found`
);
await this.SubmissionModel.updateOne(
{ _id: submissionId },
{ ...input, updatedBy: mentorId }
);
await this.mentorService.notifyMenteeOfGrading(submissionId);
}