@nestjs/common#DefaultValuePipe TypeScript Examples

The following examples show how to use @nestjs/common#DefaultValuePipe. 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: quiz.controller.ts    From nest-js-quiz-manager with MIT License 6 votes vote down vote up
@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 #2
Source File: time-series.controller.ts    From aqualink-app with MIT License 6 votes vote down vote up
@ApiTimeSeriesResponse()
  @ApiOperation({
    summary:
      'Returns specified time series data for a specified site point of interest',
  })
  @ApiQuery({ name: 'start', example: '2021-05-18T10:20:28.017Z' })
  @ApiQuery({ name: 'end', example: '2021-05-18T10:20:28.017Z' })
  @ApiQuery({
    name: 'metrics',
    example: [Metric.BOTTOM_TEMPERATURE, Metric.TOP_TEMPERATURE],
  })
  @ApiQuery({ name: 'hourly', example: false, required: false })
  @Get('sites/:siteId/site-survey-points/:surveyPointId')
  findSurveyPointData(
    @Param() surveyPointDataDto: SurveyPointDataDto,
    @Query(
      'metrics',
      new DefaultValuePipe(Object.values(Metric)),
      ParseArrayPipe,
    )
    metrics: Metric[],
    @Query('start', ParseDatePipe) startDate?: string,
    @Query('end', ParseDatePipe) endDate?: string,
    @Query('hourly') hourly?: boolean,
  ) {
    return this.timeSeriesService.findSurveyPointData(
      surveyPointDataDto,
      metrics,
      startDate,
      endDate,
      hourly,
    );
  }
Example #3
Source File: time-series.controller.ts    From aqualink-app with MIT License 6 votes vote down vote up
@ApiTimeSeriesResponse()
  @ApiOperation({
    summary: 'Returns specified time series data for a specified site',
  })
  @ApiQuery({ name: 'start', example: '2021-05-18T10:20:28.017Z' })
  @ApiQuery({ name: 'end', example: '2021-05-18T10:20:28.017Z' })
  @ApiQuery({
    name: 'metrics',
    example: [Metric.BOTTOM_TEMPERATURE, Metric.TOP_TEMPERATURE],
  })
  @ApiQuery({ name: 'hourly', example: false, required: false })
  @Get('sites/:siteId')
  findSiteData(
    @Param() siteDataDto: SiteDataDto,
    @Query(
      'metrics',
      new DefaultValuePipe(Object.values(Metric)),
      ParseArrayPipe,
    )
    metrics: Metric[],
    @Query('start', ParseDatePipe) startDate?: string,
    @Query('end', ParseDatePipe) endDate?: string,
    @Query('hourly', ParseBoolPipe) hourly?: boolean,
  ) {
    return this.timeSeriesService.findSiteData(
      siteDataDto,
      metrics,
      startDate,
      endDate,
      hourly,
    );
  }
Example #4
Source File: post.controller.ts    From nestjs-rest-sample with GNU General Public License v3.0 5 votes vote down vote up
@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 #5
Source File: user.controller.ts    From nestjs-rest-sample with GNU General Public License v3.0 5 votes vote down vote up
@Get(':id')
  getUser(
    @Param('id', ParseObjectIdPipe) id: string,
    @Query('withPosts', new DefaultValuePipe(false)) withPosts?: boolean
  ): Observable<Partial<User>> {
    return this.userService.findById(id, withPosts);
  }
Example #6
Source File: user.controller.ts    From MyAPI with MIT License 5 votes vote down vote up
@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>
  }