How to use the @nestjs/swagger.ApiUseTags 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 kuangshp / nestjs-mysql-api / src / file / file.controller.ts View on Github external
import {
  Controller,
  Post,
  UseInterceptors,
  HttpStatus,
  UploadedFile,
  HttpCode,
} from '@nestjs/common';
import { FileInterceptor } from '@nestjs/platform-express';
import { UploadFileService } from './../core/upload-file/upload-file.service';
import { ApiUseTags, ApiOperation, ApiBearerAuth } from '@nestjs/swagger';

@ApiUseTags('file')
@ApiBearerAuth()
@Controller('file')
export class FileController {
  constructor (private readonly uploadFileService: UploadFileService) { }

  @ApiOperation({ title: '上传文件' })
  @Post()
  @HttpCode(HttpStatus.OK)
  @UseInterceptors(FileInterceptor('files'))
  uploadFile(@UploadedFile() files) {
    console.log(files);
    return this.uploadFileService.uploadFile({
      files,
      typeList: ['.png', '.pdf'],
    });
  }
github new-eden-social / new-eden-social / src / gateway-http / comment / comment.controller.ts View on Github external
import { Body, Controller, Get, HttpStatus, Param, Post, UseGuards } from '@nestjs/common';
import { ApiBearerAuth, ApiResponse, ApiUseTags } from '@nestjs/swagger';
import { AuthenticatedCharacter } from '../authentication/authentication.decorators';
import { DComment, DCommentList } from './comment.dto';
import { VCreateComment } from './comment.validate';
import { AuthenticationGuard } from '../authentication/authentication.guard';
import { Pagination, VPagination } from '@new-eden-social/pagination';
import { CORPORATION_ROLES, CorporationGrpcClient } from '@new-eden-social/services-corporation';
import { CommentGrpcClient } from '@new-eden-social/services-comment';
import { ICharacterResponse } from '@new-eden-social/services-character';
import { PostGrpcClient } from '@new-eden-social/services-post';
import { CorporationRolesGuard } from '../corporation/corporation.roles.guard';
import { CorporationRoles } from '../corporation/corporation.roles.decorator';
import { CorporationAllianceExecutorGuard } from '../corporation/corporation.allianceExecutor.guard';

@ApiUseTags('comments')
@Controller('comments')
export class CommentController {

  constructor(
    private readonly commentClient: CommentGrpcClient,
    private readonly corporationClient: CorporationGrpcClient,
  ) {
  }

  @ApiResponse({
    status: HttpStatus.CREATED,
    type: DComment,
    description: 'Post as Character',
  })
  @ApiBearerAuth()
  @UseGuards(AuthenticationGuard)
github NarHakobyan / awesome-nest-boilerplate / src / modules / user / user.controller.ts View on Github external
} from '@nestjs/common';
import { ApiBearerAuth, ApiResponse, ApiUseTags } from '@nestjs/swagger';

import { RoleType } from '../../common/constants/role-type';
import { AuthUser } from '../../decorators/auth-user.decorator';
import { Roles } from '../../decorators/roles.decorator';
import { AuthGuard } from '../../guards/auth.guard';
import { RolesGuard } from '../../guards/roles.guard';
import { AuthUserInterceptor } from '../../interceptors/auth-user-interceptor.service';
import { UsersPageOptionsDto } from './dto/UsersPageOptionsDto';
import { UsersPageDto } from './dto/UsersPageDto';
import { UserEntity } from './user.entity';
import { UserService } from './user.service';

@Controller('users')
@ApiUseTags('users')
@UseGuards(AuthGuard, RolesGuard)
@UseInterceptors(AuthUserInterceptor)
@ApiBearerAuth()
export class UserController {
    constructor(private _userService: UserService) {}

    @Get('admin')
    @Roles(RoleType.USER)
    @HttpCode(HttpStatus.OK)
    async admin(@AuthUser() user: UserEntity) {
        return 'only for you admin: ' + user.firstName;
    }

    @Get('users')
    @Roles(RoleType.ADMIN)
    @HttpCode(HttpStatus.OK)
github kuangshp / nestjs-mysql-api / src / core / role / role.controller.ts View on Github external
Delete,
  Get,
  HttpCode,
  HttpStatus,
  UseInterceptors,
  Query,
} from '@nestjs/common';
import { ApiUseTags, ApiBearerAuth, ApiOperation } from '@nestjs/swagger';

import { RoleEntity } from './role.entity';
import { RoleService } from './role.service';
import { UpdateRoleDto } from './dto/update.role.dto';
import { CreateRoleDto } from './dto/create.role.dto';
import { PaginateInterceptor } from './../../shared/interceptor/paginate.interceptor';

@ApiUseTags('role')
@ApiBearerAuth()
@Controller('role')
export class RoleController {
  constructor(private readonly roleService: RoleService) {}

  @ApiOperation({ title: '添加角色' })
  @HttpCode(HttpStatus.CREATED)
  @Post()
  async create(@Body() data: CreateRoleDto): Promise {
    return this.roleService.create(data);
  }

  @ApiOperation({ title: '查询所有的角色', description: '支持分页查询' })
  @Get()
  @UseInterceptors(PaginateInterceptor)
  @HttpCode(HttpStatus.OK)
github tsmean / tsmean / backend / src / animal-list / animal-list.controller.ts View on Github external
import {FindManyOptions} from 'typeorm';
import {DeepPartial} from 'typeorm/common/DeepPartial';
import {ApiBearerAuth, ApiOperation, ApiResponse, ApiUseTags} from '@nestjs/swagger';

import {AnimalListService} from './animal-list.service';
import {LoggingInterceptor} from '../common/interceptors/logging.interceptor';
import {TransformInterceptor} from '../common/interceptors/transform.interceptor';
import {Animal} from '../animal/animal.entity';
import {apiPath} from '../api';
import {AnimalListDto} from '@tsmean/shared/src/dto/animal-list/animal-list.dto';
import {AnimalList} from './animal-list.entity';
import {User} from '../user/user.entity';
import {CurrentUser} from '../user/user.decorator';
import {Authorized} from '../common/decorators/authorized.decorator';

@ApiUseTags('Animal lists')
@UseInterceptors(LoggingInterceptor, TransformInterceptor)
@Controller(apiPath(1, 'animal-lists'))
export class AnimalListController {
  constructor(private readonly animalListService: AnimalListService) {}

  @ApiBearerAuth()
  @ApiOperation({title: 'Create animals list'})
  @ApiResponse({
    status: 201,
    description: 'The list has been successfully created.',
    type: AnimalList
  })
  @ApiResponse({status: 401, description: 'You have to be logged to create list!'})
  @Authorized()
  @Post()
  async create(@Body() createDto: AnimalListDto, @CurrentUser() currentUser?: User) {
github chanlito / simple-todos / server / app / auth / auth.controller.ts View on Github external
import { BadRequestException, Body, Controller, Post, Req } from '@nestjs/common';
import { ApiUseTags } from '@nestjs/swagger';
import { compare, genSalt, hash } from 'bcryptjs';
import { Request } from 'express';
import { sign } from 'jsonwebtoken';
import { InjectCustomRepository, InjectEntityManager } from 'nestjs-extensions';
import { EntityManager } from 'typeorm';

import { Profile, Role, User } from '../../entity';
import { UserRepository } from '../../repository';
import { SignInDto, SignUpDto } from './auth.dto';

@ApiUseTags('auth')
@Controller('auth')
export class AuthController {
  constructor(
    @InjectEntityManager() private readonly em: EntityManager,
    @InjectCustomRepository(User) private readonly userRepository: UserRepository
  ) {}

  @Post('sign-up')
  async signUp(@Body() body: SignUpDto) {
    await this.em.transaction(async em => {
      const userRole = await em.findOne(Role, { where: { name: 'user' } });
      if (!userRole) throw new Error('Role "user" is missing.');

      const user = new User();
      user.email = body.email;
      user.password = await genSalt().then(s => hash(body.password, s));
github lujakob / nestjs-realworld-example-app / src / tag / tag.controller.ts View on Github external
import {Get, Controller } from '@nestjs/common';

import { TagEntity } from './tag.entity';
import { TagService } from './tag.service';

import {
  ApiUseTags,
  ApiBearerAuth,
} from '@nestjs/swagger';

@ApiBearerAuth()
@ApiUseTags('tags')
@Controller('tags')
export class TagController {

  constructor(private readonly tagService: TagService) {}

  @Get()
  async findAll(): Promise {
    return await this.tagService.findAll();
  }

}