@nestjs/swagger#ApiResponse TypeScript Examples

The following examples show how to use @nestjs/swagger#ApiResponse. 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: plugin-newsletter.controller.ts    From Cromwell with MIT License 7 votes vote down vote up
@Post('subscribe')
    /** Use ThrottlerGuard to limit number of requests from one IP address. Allow max 4 requests in 20 seconds: */
    @UseGuards(ThrottlerGuard)
    @Throttle(4, 20)
    @ApiOperation({ description: 'Post email to subscribe for newsletters' })
    @ApiResponse({
        status: 200,
        type: Boolean,
    })
    @ApiBody({ type: PluginNewsletterSubscription })
    @ApiForbiddenResponse({ description: 'Forbidden.' })
    async placeSubscription(@Body() input: PluginNewsletterSubscription): Promise<boolean | undefined> {
        const email = input?.email;
        if (!email || !/\S+@\S+\.\S+/.test(email)) {
            throw new HttpException(`Invalid email`, HttpStatus.BAD_REQUEST);
        }

        const hasSubscribed = await getManager().findOne(PluginNewsletter, {
            where: {
                email
            }
        });
        if (hasSubscribed) return true;

        const newsletter = new PluginNewsletter();
        newsletter.email = email;
        await getManager().save(newsletter);
        return true;
    }
Example #2
Source File: attribution.ts    From barista with Apache License 2.0 6 votes vote down vote up
@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);
      }
    }
  }