Skip to content

Commit

Permalink
All the codes referred to swagger routes were moved from the company
Browse files Browse the repository at this point in the history
controller to separate fil
  • Loading branch information
PatrickOtero committed Sep 7, 2023
1 parent c8c095c commit 0caa13a
Show file tree
Hide file tree
Showing 10 changed files with 277 additions and 178 deletions.
199 changes: 21 additions & 178 deletions src/modules/company/company.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import {
Controller,
Delete,
Get,
HttpStatus,
Param,
Patch,
Post,
Expand All @@ -12,22 +11,25 @@ import {
Res,
UploadedFile,
UseGuards,
UseInterceptors,
UseInterceptors
} from '@nestjs/common';
import { AuthGuard } from '@nestjs/passport';
import { FileInterceptor } from '@nestjs/platform-express';
import {
ApiBearerAuth,
ApiBody,
ApiOperation,
ApiParam,
ApiResponse,
ApiTags,
ApiTags
} from '@nestjs/swagger';
import { Response } from 'express';
import { CompaniesEntity } from 'src/database/entities/companies.entity';
import { BadRequestSwagger } from '../../shared/Swagger/bad-request.swagger';
import { UnauthorizedSwagger } from '../../shared/Swagger/unauthorized.swagger';
import { ActivateCompanySwagger } from 'src/shared/Swagger/company/activate-company.swagger';
import { CreateCompanySwagger } from 'src/shared/Swagger/company/create-company.swagger';
import { DeleteCompanyByIdSwagger } from 'src/shared/Swagger/company/delete-company-by-id.swagger';
import { GetAllCompaniesSwagger } from 'src/shared/Swagger/company/get-all-companies.swagger';
import { GetCompanyByIdSwagger } from 'src/shared/Swagger/company/get-company-by-id.swagger';
import { RecoverPasswordByEmailSwagger } from 'src/shared/Swagger/company/recovery-password-by-email.swagger';
import { UpdateCompanyByIdSwagger } from 'src/shared/Swagger/company/update-company-by-id.swagger';
import { UpdatePasswordAfterRecoveryEmailSwagger } from 'src/shared/Swagger/company/update-password-after-recovery-email.swagger';
import { UpdatePasswordSwagger } from 'src/shared/Swagger/company/update-password.swagger';
import { PageOptionsDto } from '../../shared/pagination';
import GetEntity from '../../shared/pipes/pipe-entity.pipe';
import { LoggedCompany } from '../auth/decorator/logged-company.decorator';
Expand Down Expand Up @@ -65,24 +67,7 @@ export class CompanyController {
) {}

@Post()
@ApiResponse({
status: HttpStatus.OK,
description: 'Exemplo do retorno de sucesso da rota',
type: CreateCompanyDto,
})
@ApiResponse({
status: HttpStatus.UNAUTHORIZED,
description: 'Modelo de erro',
type: UnauthorizedSwagger,
})
@ApiResponse({
status: HttpStatus.BAD_REQUEST,
description: 'Modelo de erro',
type: BadRequestSwagger,
})
@ApiOperation({
summary: 'Cadastrar uma empresa.',
})
@CreateCompanySwagger()
async createCompany(
@Body() createcompany: CreateCompanyDto,
@Res() res: Response,
Expand All @@ -95,46 +80,13 @@ export class CompanyController {
}

@Get()
@ApiResponse({
status: HttpStatus.OK,
description: 'Exemplo do retorno de sucesso da rota',
type: PageOptionsDto,
})
@ApiResponse({
status: HttpStatus.UNAUTHORIZED,
description: 'Modelo de erro',
type: UnauthorizedSwagger,
})
@ApiResponse({
status: HttpStatus.BAD_REQUEST,
description: 'Modelo de erro',
type: BadRequestSwagger,
})
@ApiOperation({
summary: 'Buscar todas as empresas.',
})
@GetAllCompaniesSwagger()
async getAllCompanies(@Query() pageOptionsDto: PageOptionsDto) {
return this.findAllCompanyService.execute(pageOptionsDto);
}

@Get(':id')
@ApiParam({
name: 'id',
type: 'string',
})
@ApiResponse({
status: HttpStatus.UNAUTHORIZED,
description: 'Modelo de erro',
type: UnauthorizedSwagger,
})
@ApiResponse({
status: HttpStatus.BAD_REQUEST,
description: 'Modelo de erro',
type: BadRequestSwagger,
})
@ApiOperation({
summary: 'Buscar uma empresa por id.',
})
@GetCompanyByIdSwagger()
async getcompanyById(
@Param('id', new GetEntity(CompaniesEntity, ['jobs']))
company: CompaniesEntity,
Expand All @@ -146,36 +98,7 @@ export class CompanyController {
@UseGuards(AuthGuard())
@UseInterceptors(FileInterceptor('file'))
@Put('edit')
@ApiBody({
description: 'Upload images',
schema: {
type: 'object',
properties: {
file: {
type: 'string',
format: 'binary',
},
},
},
})
@ApiResponse({
status: HttpStatus.OK,
description: 'Exemplo do retorno de sucesso da rota',
type: UpdateCompanyDto,
})
@ApiResponse({
status: HttpStatus.UNAUTHORIZED,
description: 'Modelo de erro',
type: UnauthorizedSwagger,
})
@ApiResponse({
status: HttpStatus.BAD_REQUEST,
description: 'Modelo de erro',
type: BadRequestSwagger,
})
@ApiOperation({
summary: 'Atualizar uma empresa por id.',
})
@UpdateCompanyByIdSwagger()
async updatecompanyById(
@LoggedCompany() company: CompaniesEntity,
@Body() updateCompanyDto: UpdateCompanyDto,
Expand All @@ -191,25 +114,8 @@ export class CompanyController {
}

@Patch('recovery-password')
@ApiResponse({
status: HttpStatus.OK,
description: 'Exemplo do retorno de sucesso da rota',
type: EmailDto,
})
@ApiResponse({
status: HttpStatus.UNAUTHORIZED,
description: 'Modelo de erro',
type: UnauthorizedSwagger,
})
@ApiResponse({
status: HttpStatus.BAD_REQUEST,
description: 'Modelo de erro',
type: BadRequestSwagger,
})
@ApiOperation({
summary: 'Send email to recovery password.',
})
async recoveryPasswordSendEmail(
@RecoverPasswordByEmailSwagger()
async recoverPasswordByEmail(
@Body() { email }: EmailDto,
@Res() res: Response,
) {
Expand All @@ -219,24 +125,7 @@ export class CompanyController {
}

@Patch('update_password_email')
@ApiResponse({
status: HttpStatus.OK,
description: 'Exemplo do retorno de sucesso da rota',
type: CreatePasswordHashDto,
})
@ApiResponse({
status: HttpStatus.UNAUTHORIZED,
description: 'Modelo de erro',
type: UnauthorizedSwagger,
})
@ApiResponse({
status: HttpStatus.BAD_REQUEST,
description: 'Modelo de erro',
type: BadRequestSwagger,
})
@ApiOperation({
summary: 'Company update password.',
})
@UpdatePasswordAfterRecoveryEmailSwagger()
async updatePasswordByEmail(
@Body() updatePassword: CreatePasswordHashDto,
@Res() res: Response,
Expand All @@ -250,24 +139,7 @@ export class CompanyController {
@Patch('update_password')
@UseGuards(AuthGuard())
@ApiBearerAuth()
@ApiResponse({
status: HttpStatus.OK,
description: 'Exemplo do retorno de sucesso da rota',
type: CreatePasswordHashDto,
})
@ApiResponse({
status: HttpStatus.UNAUTHORIZED,
description: 'Modelo de erro',
type: UnauthorizedSwagger,
})
@ApiResponse({
status: HttpStatus.BAD_REQUEST,
description: 'Modelo de erro',
type: BadRequestSwagger,
})
@ApiOperation({
summary: 'Company update password without recovery e-mail.',
})
@UpdatePasswordSwagger()
async updatePassword(
@LoggedCompany() company: CompaniesEntity,
@Body() updatePassword: UpdateMyPasswordDto,
Expand All @@ -281,43 +153,14 @@ export class CompanyController {
}

@Patch(':id')
@ApiResponse({
status: HttpStatus.UNAUTHORIZED,
description: 'Modelo de erro',
type: UnauthorizedSwagger,
})
@ApiResponse({
status: HttpStatus.BAD_REQUEST,
description: 'Modelo de erro',
type: BadRequestSwagger,
})
@ApiOperation({
summary: 'Ativar uma empresa pelo ID',
})
@ActivateCompanySwagger()
async activateCompany(@Param('id') id: string, @Res() res: Response) {
const { data, status } = await this.activateCompanyService.execute(id);
return res.status(status).send(data);
}

@Delete(':id')
@ApiResponse({
status: HttpStatus.OK,
description: 'Exemplo do retorno de sucesso da rota',
type: CompanyIdDto,
})
@ApiResponse({
status: HttpStatus.UNAUTHORIZED,
description: 'Modelo de erro',
type: UnauthorizedSwagger,
})
@ApiResponse({
status: HttpStatus.BAD_REQUEST,
description: 'Modelo de erro',
type: BadRequestSwagger,
})
@ApiOperation({
summary: 'Excluir uma empresa por id.',
})
@DeleteCompanyByIdSwagger()
async deleteCompanyById(@Param() { id }: CompanyIdDto, @Res() res: Response) {
const { data, status } = await this.deleteCompanyService.execute(id);
return res.status(status).send(data);
Expand Down
22 changes: 22 additions & 0 deletions src/shared/Swagger/company/activate-company.swagger.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { HttpStatus, applyDecorators } from "@nestjs/common";
import { ApiOperation, ApiResponse } from "@nestjs/swagger";
import { UnauthorizedSwagger } from "../unauthorized.swagger";
import { BadRequestSwagger } from "../bad-request.swagger";

export function ActivateCompanySwagger() {
return applyDecorators(
ApiResponse({
status: HttpStatus.UNAUTHORIZED,
description: 'Modelo de erro',
type: UnauthorizedSwagger,
}),
ApiResponse({
status: HttpStatus.BAD_REQUEST,
description: 'Modelo de erro',
type: BadRequestSwagger,
}),
ApiOperation({
summary: 'Ativar uma empresa pelo ID',
})
)
}
28 changes: 28 additions & 0 deletions src/shared/Swagger/company/create-company.swagger.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { HttpStatus, applyDecorators } from "@nestjs/common";
import { ApiOperation, ApiResponse } from "@nestjs/swagger";
import { CreateCompanyDto } from "src/modules/company/dtos/create-company.dto";
import { UnauthorizedSwagger } from "../unauthorized.swagger";
import { BadRequestSwagger } from "../bad-request.swagger";

export function CreateCompanySwagger() {
return applyDecorators(
ApiResponse({
status: HttpStatus.OK,
description: 'Exemplo do retorno de sucesso da rota',
type: CreateCompanyDto,
}),
ApiResponse({
status: HttpStatus.UNAUTHORIZED,
description: 'Modelo de erro',
type: UnauthorizedSwagger,
}),
ApiResponse({
status: HttpStatus.BAD_REQUEST,
description: 'Modelo de erro',
type: BadRequestSwagger,
}),
ApiOperation({
summary: 'Cadastrar uma empresa.',
})
)
}
28 changes: 28 additions & 0 deletions src/shared/Swagger/company/delete-company-by-id.swagger.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { HttpStatus, applyDecorators } from "@nestjs/common";
import { ApiOperation, ApiResponse } from "@nestjs/swagger";
import { CompanyIdDto } from "src/modules/company/dtos/company-id.dto";
import { UnauthorizedSwagger } from "../unauthorized.swagger";
import { BadRequestSwagger } from "../bad-request.swagger";

export function DeleteCompanyByIdSwagger() {
return applyDecorators(
ApiResponse({
status: HttpStatus.OK,
description: 'Exemplo do retorno de sucesso da rota',
type: CompanyIdDto,
}),
ApiResponse({
status: HttpStatus.UNAUTHORIZED,
description: 'Modelo de erro',
type: UnauthorizedSwagger,
}),
ApiResponse({
status: HttpStatus.BAD_REQUEST,
description: 'Modelo de erro',
type: BadRequestSwagger,
}),
ApiOperation({
summary: 'Excluir uma empresa por id.',
})
)
}
28 changes: 28 additions & 0 deletions src/shared/Swagger/company/get-all-companies.swagger.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { HttpStatus, applyDecorators } from "@nestjs/common";
import { ApiOperation, ApiResponse } from "@nestjs/swagger";
import { BadRequestSwagger } from "../bad-request.swagger";
import { UnauthorizedSwagger } from "../unauthorized.swagger";
import { PageOptionsDto } from "src/shared/pagination";

export function GetAllCompaniesSwagger() {
return applyDecorators(
ApiResponse({
status: HttpStatus.OK,
description: 'Exemplo do retorno de sucesso da rota',
type: PageOptionsDto,
}),
ApiResponse({
status: HttpStatus.UNAUTHORIZED,
description: 'Modelo de erro',
type: UnauthorizedSwagger,
}),
ApiResponse({
status: HttpStatus.BAD_REQUEST,
description: 'Modelo de erro',
type: BadRequestSwagger,
}),
ApiOperation({
summary: 'Buscar todas as empresas.',
})
)
}
Loading

0 comments on commit 0caa13a

Please sign in to comment.