How to use the @nestjs/swagger.ApiResponse function in @nestjs/swagger

To help you get started, we’ve selected a few @nestjs/swagger examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github qas / examples-nodejs-cqrs-es-swagger / src / users / controllers / users.controller.ts View on Github external
return this.usersService.createUser({...{userId}, ...userDto});
  }

  /* Update User */
  /*--------------------------------------------*/
  @ApiOperation({ title: 'Update User' })
  @ApiResponse({ status: 200, description: 'Update User.' })
  @Put(':userId')
  async updateUser(@Param() userId: UserIdRequestParamsDto, @Body() userDto: UserDto) {
    return this.usersService.updateUser({...userId, ...userDto});
  }

  /* Delete User */
  /*--------------------------------------------*/
  @ApiOperation({ title: 'Delete User' })
  @ApiResponse({ status: 200, description: 'Delete User.' })
  @Delete(':userId')
  async deleteUser(@Param() userId: UserIdRequestParamsDto) {
    return this.usersService.deleteUser(userId);
  }

  /* TODO: List Users */
  /*--------------------------------------------*/
  @ApiOperation({ title: 'List Users' })
  @ApiResponse({ status: 200, description: 'List Users.' })
  @Get()
  async findUsers(@Param() param) {
    return this.usersService.findUsers();
  }

  /* TODO: Find User */
  /*--------------------------------------------*/
github lujakob / nestjs-realworld-example-app / src / article / article.controller.ts View on Github external
@Post(':slug/comments')
  async createComment(@Param('slug') slug, @Body('comment') commentData: CreateCommentDto) {
    return await this.articleService.addComment(slug, commentData);
  }

  @ApiOperation({ title: 'Delete comment' })
  @ApiResponse({ status: 201, description: 'The article has been successfully deleted.'})
  @ApiResponse({ status: 403, description: 'Forbidden.' })
  @Delete(':slug/comments/:id')
  async deleteComment(@Param() params) {
    const {slug, id} = params;
    return await this.articleService.deleteComment(slug, id);
  }

  @ApiOperation({ title: 'Favorite article' })
  @ApiResponse({ status: 201, description: 'The article has been successfully favorited.'})
  @ApiResponse({ status: 403, description: 'Forbidden.' })
  @Post(':slug/favorite')
  async favorite(@User('id') userId: number, @Param('slug') slug) {
    return await this.articleService.favorite(userId, slug);
  }

  @ApiOperation({ title: 'Unfavorite article' })
  @ApiResponse({ status: 201, description: 'The article has been successfully unfavorited.'})
  @ApiResponse({ status: 403, description: 'Forbidden.' })
  @Delete(':slug/favorite')
  async unFavorite(@User('id') userId: number, @Param('slug') slug) {
    return await this.articleService.unFavorite(userId, slug);
  }

  @ApiOperation({ title: 'Get article feed' })
  @ApiResponse({ status: 200, description: 'Return article feed.'})
github charjac / nest-boilerplate / src / auth / entities / account.controller.ts View on Github external
@Query(new FindQueryPipe(), new ValidationPipe())
    query: FindOneQuery,
    @Response() res: ExpressResponse,
  ) {
    const user = await this.accountRepository.findOneById(id, query);

    if (!user) {
      res.status(HttpStatus.NO_CONTENT).json();
    } else {
      res.json(user);
    }
  }

  @Delete(':id')
  @UseGuards(IsAccountOwnerGuard)
  @ApiResponse({
    description: 'The account has been deleted',
    status: 200,
  })
  @ApiResponse({
    description: "The account doesn't exist",
    status: 204,
  })
  public async remove(
    @Param('id') id: string,
    @Response() res: ExpressResponse,
  ) {
    const value = await this.accountRepository.deleteById(id);

    if (value) {
      res.json();
    } else {
github lonelyhentai / minellius / server / src / role / controllers / groups.controller.ts View on Github external
try {
      return plainToClass(
        OutGroupDto,
        await this.service.delete({
          id,
        }),
      );
    } catch (error) {
      throw error;
    }
  }

  @Roles('isSuperuser')
  @Permissions('read_group')
  @HttpCode(HttpStatus.OK)
  @ApiResponse({
    status: HttpStatus.OK,
    type: OutGroupDto,
    description: '',
  })
  @ApiResponse({ status: HttpStatus.FORBIDDEN, description: 'Forbidden.' })
  @ApiImplicitParam({ name: 'id', type: Number })
  @Get(':id')
  async findById(@Param('id', new ParseIntPipe()) id) {
    try {
      return plainToClass(
        OutGroupDto,
        await this.service.findById({
          id,
        }),
      );
    } catch (error) {
github charjac / nest-boilerplate / src / auth / entities / user.controller.ts View on Github external
const count = await this.userRepository.count();
    const users = !!query.ids
      ? await this.userRepository.findByIds(query.ids)
      : await this.userRepository.find(options);
    res.set('Content-Range', `users ${users.length}/${count}`);
    res.json(users);
  }

  @Get(':id')
  @UseGuards(IsUserOwnerGuard)
  @ApiResponse({
    description: 'The user has been retrieved',
    status: 200,
    type: User,
  })
  @ApiResponse({
    description: 'The user has not been retrieved',
    status: 204,
  })
  public async findOne(
    @Param('id') id: string,
    @Query(new FindQueryPipe(), new ValidationPipe())
    query: FindOneQuery,
    @Response() res: ExpressResponse,
  ) {
    const user = await this.userRepository.findOneById(id, query);

    if (!user) {
      res.status(HttpStatus.NO_CONTENT).json();
    } else {
      res.json(user);
    }
github devonfw / my-thai-star / node / src / management / order / order.controller.ts View on Github external
import { Order } from './models/order.entity';
import { ApiException } from 'shared/api-exception.model';
import { GetOperationId } from 'shared/utilities/get-operation-id';
import { AuthGuard } from '@nestjs/passport';
import { RolesGuard } from 'shared/guards/roles.guard';
import { Roles } from 'shared/decorators/role.decorator';
import { UserRole } from 'management/user/models/user-role.enum';

@Controller('/services/rest/ordermanagement/v1/order')
@ApiUseTags('Order')
export class OrderController {
  constructor(private readonly service: OrderService) {}

  @Post()
  @ApiResponse({ status: HttpStatus.OK, type: Order })
  @ApiResponse({ status: HttpStatus.BAD_REQUEST, type: ApiException })
  @ApiOperation(GetOperationId('Order', 'Create'))
  async createOrder(@Body() input: OrderListInfo): Promise {
    try {
      return await this.service.createOrder(input);
    } catch (error) {
      throw error;
    }
  }

  @Post('search')
  @UseGuards(AuthGuard('jwt'), RolesGuard)
  @Roles(UserRole.Waiter)
  @ApiResponse({ status: HttpStatus.OK /*, type: Response */ })
  @ApiResponse({ status: HttpStatus.BAD_REQUEST, type: ApiException })
  @ApiOperation(GetOperationId('Order', 'Search'))
  async getAll(@Body() input: CustomOrderFilter): Promise> {
github lonelyhentai / minellius / server / src / auth / controllers / auth.controller.ts View on Github external
status: HttpStatus.OK,
    type: UserTokenDto,
    description:
      'API View that checks the veracity of a token, returning the token if it is valid.',
  })
  async requestJsonWebTokenAfterSignIn(
    @Req() req,
    @Body() signInDto: SignInDto,
  ): Promise {
    const token = await this.tokenService.create(req.user);
    return plainToClass(UserTokenDto, { user: req.user, token });
  }

  @HttpCode(HttpStatus.CREATED)
  @Post('signup')
  @ApiResponse({
    status: HttpStatus.OK,
    type: UserTokenDto,
    description: `API View that receives a POST with a user's username and password.
        Returns a JSON Web Token that can be used for authenticated requests.`,
  })
  async requestJsonWebTokenAfterSignUp(
    @Req() req,
    @Body() signUpDto: SignUpDto,
  ): Promise {
    const token = await this.tokenService.create(req.user);
    return plainToClass(UserTokenDto, { user: req.user, token });
  }

  @HttpCode(HttpStatus.OK)
  @Post('info')
  @ApiResponse({
github new-eden-social / new-eden-social / src / gateway / follow / follow.controller.ts View on Github external
@Post('corporation/:corporationId')
  public async followCorporation(
    @Param('corporationId') corporationId: number,
    @AuthenticatedCharacter() follower: ICharacterResponse,
  ): Promise {
    const corporation = await this.corporationClient.service.get(corporationId);
    const follow = await this.followService.checkIfFolowingCorporation(follower, corporation);

    if (follow) {
      await this.followService.unfollow(follow);
    }

    await this.followService.followCorporation(follower, corporation);
  }

  @ApiResponse({
    status: HttpStatus.OK,
    description: 'Follow an Alliance',
  })
  @ApiBearerAuth()
  @UseGuards(AuthenticationGuard)
  @Post('alliance/:allianceId')
  public async followAlliance(
    @Param('allianceId') allianceId: number,
    @AuthenticatedCharacter() follower: ICharacterResponse,
  ): Promise {
    const alliance = await this.allianceClient.service.get(allianceId).toPromise();
    const follow = await this.followService.checkIfFolowingAlliance(follower, alliance);

    if (follow) {
      await this.followService.unfollow(follow);
    }