@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 9 votes vote down vote up
@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: users.controller.ts    From nest-js-boilerplate with MIT License 8 votes vote down vote up
@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 #3
Source File: project.controller.ts    From barista with Apache License 2.0 7 votes vote down vote up
@Get('/:id/obligations')
  @UseInterceptors(CrudRequestInterceptor)
  async obligations(@Param('id') id: string): Promise<any> {
    const project = await this.service.db.findOne(Number(id));
    if (project) {
      return this.service.distinctObligations(project);
    } else {
      return [];
    }
  }
Example #4
Source File: card.controller.ts    From 42_checkIn with GNU General Public License v3.0 6 votes vote down vote up
@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 #5
Source File: doubt.controller.ts    From edu-server with MIT License 6 votes vote down vote up
@Delete('/deleteDoubtAnswer/:doubtId/:doubtAnswerId')
  @ApiParam(doubtAnswerId)
  @ApiParam(doubtId)
  @ApiCreatedResponse(responsedoc.deleteDoubtAnswer)
  @ApiOperation({ summary: 'Delete doubt Answer by id' })
  async deleteDoubtAnswer(
    @Param('doubtId') doubtId: Schema.Types.ObjectId,
    @Param('doubtAnswerId') doubtAnswerId: Schema.Types.ObjectId,
  ): Promise<DoubtAnswer> {
    return await this.doubtService.deleteDoubtAnswer(doubtId, doubtAnswerId);
  }
Example #6
Source File: tracks.controller.ts    From codeclannigeria-backend with MIT License 6 votes vote down vote up
@Put(':trackId/reactivate')
  @UseGuards(JwtAuthGuard, RolesGuard)
  @Roles(UserRole.ADMIN)
  @ApiResponse({ status: HttpStatus.OK })
  @ApiBearerAuth()
  async enableTrack(@Param('trackId') trackId: string): Promise<void> {
    const track = await this.trackService.findByIdAsync(trackId);

    if (!track) throw new NotFoundException(`Track with ${trackId} not found`);

    await this.trackService.activateTrack(trackId);
  }
Example #7
Source File: organizations.controller.ts    From nestjs-rest-microservices with MIT License 6 votes vote down vote up
@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 #8
Source File: users.controller.ts    From aqualink-app with MIT License 6 votes vote down vote up
@ApiBearerAuth()
  @ApiNestNotFoundResponse('No user was found with the specified id')
  @ApiOperation({ summary: 'Deletes specified user' })
  @ApiParam({ name: 'id', example: 1 })
  @OverrideLevelAccess(AdminLevel.SuperAdmin)
  @Delete(':id')
  delete(@Param('id', ParseIntPipe) id: number): Promise<void> {
    return this.usersService.delete(id);
  }
Example #9
Source File: TodoListEventsController.ts    From remix-hexagonal-architecture with MIT License 6 votes vote down vote up
@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 #10
Source File: build.controller.ts    From amplication with Apache License 2.0 6 votes vote down vote up
@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: LocalBlueprintController.ts    From rewind with MIT License 6 votes vote down vote up
@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 #12
Source File: user.controller.ts    From uniauth-backend with MIT License 6 votes vote down vote up
/**
   * Responds to: _PUT(`/:id`)_
   *
   * To update details of user
   */

  /**
   * Responds to: _DELETE(`/:id`)_
   *
   * To delete the user
   */
  @Delete(':id')
  remove(@Param('id') id: string) {
    return this.userService.remove(+id);
  }
Example #13
Source File: project.controller.ts    From barista with Apache License 2.0 6 votes vote down vote up
@Get('/:id/stats/severities')
  @UseInterceptors(CrudRequestInterceptor)
  @ApiResponse({ status: 200, type: [ProjectDistinctSeverityDto] })
  async severities(@Param('id') id: string): Promise<ProjectDistinctSeverityDto[]> {
    const project = await this.service.db.findOne(Number(id));
    if (project) {
      return this.service.distinctSeverities(project);
    } else {
      return [];
    }
  }
Example #14
Source File: users.controller.ts    From nest-js-boilerplate with MIT License 6 votes vote down vote up
@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 #15
Source File: project.controller.ts    From barista with Apache License 2.0 6 votes vote down vote up
@Get('/:id/stats/vulnerabilities')
  @UseInterceptors(CrudRequestInterceptor)
  @ApiResponse({ status: 200, type: [ProjectDistinctVulnerabilityDto] })
  async vulnerabilities(@Param('id') id: string): Promise<ProjectDistinctVulnerabilityDto[]> {
    const project = await this.service.db.findOne(Number(id));
    if (project) {
      return this.service.distinctVulnerabilities(project);
    } else {
      return [];
    }
  }
Example #16
Source File: users.controller.ts    From nest-js-boilerplate with MIT License 6 votes vote down vote up
@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 #17
Source File: project.controller.ts    From barista with Apache License 2.0 6 votes vote down vote up
@Get('/:id/stats/project-scan-status')
  @UseInterceptors(CrudRequestInterceptor)
  @ApiResponse({ status: 200, type: ProjectScanStateDto })
  async projectScanStatus(@Param('id') id: string): Promise<ProjectScanStateDto> {
    const project = await this.service.db.findOne(Number(id));
    const projectStatus = new ProjectScanStateDto();

    projectStatus.licenseStatus = await ProjectScanStatusTypeService.Unknown();
    projectStatus.securityStatus = await ProjectScanStatusTypeService.Unknown();

    if (project) {
      projectStatus.projectId = project.id;
      projectStatus.licenseStatus = await this.service.highestLicenseStatus(project);
      projectStatus.securityStatus = await this.service.highestSecurityStatus(project);
    }

    return projectStatus;
  }