@nestjs/swagger#ApiOperation TypeScript Examples

The following examples show how to use @nestjs/swagger#ApiOperation. 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 8 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: 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 #3
Source File: user.controller.ts    From edu-server with MIT License 6 votes vote down vote up
@Put('/enrolledCourses/:courseId')
  @ApiOperation({ summary: 'user updating enrolled courses' })
  @ApiCreatedResponse(responsedoc.updateEnrolledCourses)
  async updateEnrolledCourses(
    @Param('courseId') courseId: Schema.Types.ObjectId,
    @Body() updateEnrolledDto: UpdateEnrolledDTO,
  ) {
    return await this.userService.updateCourse(updateEnrolledDto, courseId);
  }
Example #4
Source File: api-swagger-operation.decorator.ts    From codeclannigeria-backend with MIT License 6 votes vote down vote up
ApiSwaggerOperation = (options: {
  title: string;
  description?: string;
  operationId?: string;
  deprecated?: boolean;
}): MethodDecorator => {
  return (target, propertyKey: string, descriptor: PropertyDescriptor) => {
    const controllerName = target.constructor.name;
    ApiOperation({
      ...options,
      operationId: `${controllerName.substr(
        0,
        controllerName.indexOf('Controller'),
      )}_${propertyKey}`,
    })(target, propertyKey, descriptor);
  };
}
Example #5
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 #6
Source File: find-users.http.controller.ts    From domain-driven-hexagon with MIT License 6 votes vote down vote up
@Get(routesV1.user.root)
  @ApiOperation({ summary: 'Find users' })
  @ApiResponse({
    status: HttpStatus.OK,
    type: UserResponse,
  })
  async findUsers(@Body() request: FindUsersRequest): Promise<UserResponse[]> {
    const query = new FindUsersQuery(request);
    const result: Result<UserEntity[], Error> = await this.queryBys.execute(
      query,
    );

    /* Returning Response classes which are responsible
       for whitelisting data that is sent to the user */
    return result.unwrap().map(user => new UserResponse(user));
  }
Example #7
Source File: mock.controller.ts    From Cromwell with MIT License 6 votes vote down vote up
@Get('all')
    @ApiOperation({ description: 'Use all available mocks' })
    @ApiResponse({
        status: 200,
        type: Boolean,
    })
    @ApiForbiddenResponse({ description: 'Forbidden.' })
    async mockAll(): Promise<boolean> {
        logger.log('MockController::mockAll');

        return this.mockService.mockAll();
    }