diff --git a/luna-backend/src/application/business/ambientes/ambiente/ambiente.controller.ts b/luna-backend/src/application/business/ambientes/ambiente/ambiente.controller.ts index fa5e2568..1424c983 100644 --- a/luna-backend/src/application/business/ambientes/ambiente/ambiente.controller.ts +++ b/luna-backend/src/application/business/ambientes/ambiente/ambiente.controller.ts @@ -1,6 +1,5 @@ -import { Controller, Delete, Get, Param, ParseUUIDPipe, Patch, Post, Put, UploadedFile, UseInterceptors } from '@nestjs/common'; -import { FileInterceptor } from '@nestjs/platform-express'; -import { ApiBody, ApiConsumes, ApiTags } from '@nestjs/swagger'; +import { Controller, Delete, Get, Param, ParseUUIDPipe, Patch, Post, Put, UploadedFile } from '@nestjs/common'; +import { ApiTags } from '@nestjs/swagger'; import { Paginate, PaginateQuery } from 'nestjs-paginate'; import * as Dto from '../../(spec)'; import { IContextoDeAcesso } from '../../../../domain'; @@ -16,6 +15,7 @@ import { HttpDtoParam, getSearchInputFromPaginateQuery, } from '../../../../infrastructure'; +import { DtoOperationSaveFile } from '../../../../infrastructure/api-documentate/DtoOperation'; import { AmbienteService } from './ambiente.service'; import { AmbienteOperations } from './dtos/ambiente.operations'; @@ -84,28 +84,7 @@ export class AmbienteController { } @Put('/:id/imagem/capa') - @ApiConsumes('multipart/form-data') - @ApiBody({ - schema: { - type: 'object', - required: ['file'], - properties: { - file: { - type: 'string', - format: 'binary', - nullable: false, - }, - }, - }, - }) - @UseInterceptors( - FileInterceptor('file', { - limits: { - files: 1, - fileSize: 10 * 1024 * 1024, - }, - }), - ) + @DtoOperationSaveFile() async blocoImagemCapaSave( // @ContextoDeAcessoHttp() contextoDeAcesso: IContextoDeAcesso, diff --git a/luna-backend/src/application/business/ambientes/bloco/bloco.controller.ts b/luna-backend/src/application/business/ambientes/bloco/bloco.controller.ts index 81f7236a..c811f4cc 100644 --- a/luna-backend/src/application/business/ambientes/bloco/bloco.controller.ts +++ b/luna-backend/src/application/business/ambientes/bloco/bloco.controller.ts @@ -1,6 +1,5 @@ -import { Controller, Delete, Get, Param, ParseUUIDPipe, Patch, Post, Put, UploadedFile, UseInterceptors } from '@nestjs/common'; -import { FileInterceptor } from '@nestjs/platform-express'; -import { ApiBody, ApiConsumes, ApiTags } from '@nestjs/swagger'; +import { Controller, Delete, Get, Param, ParseUUIDPipe, Patch, Post, Put, UploadedFile } from '@nestjs/common'; +import { ApiTags } from '@nestjs/swagger'; import { Paginate, PaginateQuery } from 'nestjs-paginate'; import * as Dto from '../../(spec)'; import { IContextoDeAcesso } from '../../../../domain'; @@ -11,6 +10,7 @@ import { DtoOperationFindAll, DtoOperationFindOne, DtoOperationGetFile, + DtoOperationSaveFile, DtoOperationUpdate, HttpDtoBody, HttpDtoParam, @@ -84,28 +84,7 @@ export class BlocoController { } @Put('/:id/imagem/capa') - @ApiConsumes('multipart/form-data') - @ApiBody({ - schema: { - type: 'object', - required: ['file'], - properties: { - file: { - type: 'string', - format: 'binary', - nullable: false, - }, - }, - }, - }) - @UseInterceptors( - FileInterceptor('file', { - limits: { - files: 1, - fileSize: 10 * 1024 * 1024, - }, - }), - ) + @DtoOperationSaveFile() async blocoImagemCapaSave( // @ContextoDeAcessoHttp() contextoDeAcesso: IContextoDeAcesso, diff --git a/luna-backend/src/application/business/autenticacao/usuario/usuario.controller.ts b/luna-backend/src/application/business/autenticacao/usuario/usuario.controller.ts index fe47718c..73abd791 100644 --- a/luna-backend/src/application/business/autenticacao/usuario/usuario.controller.ts +++ b/luna-backend/src/application/business/autenticacao/usuario/usuario.controller.ts @@ -1,6 +1,5 @@ -import { Controller, Delete, Get, Param, ParseUUIDPipe, Patch, Post, Put, UploadedFile, UseInterceptors } from '@nestjs/common'; -import { FileInterceptor } from '@nestjs/platform-express'; -import { ApiBody, ApiConsumes, ApiTags } from '@nestjs/swagger'; +import { Controller, Delete, Get, Param, ParseUUIDPipe, Patch, Post, Put, UploadedFile } from '@nestjs/common'; +import { ApiTags } from '@nestjs/swagger'; import * as Dto from '../../(spec)'; import { IContextoDeAcesso } from '../../../../domain'; import { @@ -10,6 +9,7 @@ import { DtoOperationFindAll, DtoOperationFindOne, DtoOperationGetFile, + DtoOperationSaveFile, DtoOperationUpdate, HttpDtoBody, HttpDtoParam, @@ -82,28 +82,7 @@ export class UsuarioController { } @Put('/:id/imagem/capa') - @ApiConsumes('multipart/form-data') - @ApiBody({ - schema: { - type: 'object', - required: ['file'], - properties: { - file: { - type: 'string', - format: 'binary', - nullable: false, - }, - }, - }, - }) - @UseInterceptors( - FileInterceptor('file', { - limits: { - files: 1, - fileSize: 10 * 1024 * 1024, - }, - }), - ) + @DtoOperationSaveFile() async usuarioImagemCapaSave( // @ContextoDeAcessoHttp() contextoDeAcesso: IContextoDeAcesso, @@ -126,28 +105,7 @@ export class UsuarioController { } @Put('/:id/imagem/perfil') - @ApiConsumes('multipart/form-data') - @ApiBody({ - schema: { - type: 'object', - required: ['file'], - properties: { - file: { - type: 'string', - format: 'binary', - nullable: false, - }, - }, - }, - }) - @UseInterceptors( - FileInterceptor('file', { - limits: { - files: 1, - fileSize: 10 * 1024 * 1024, - }, - }), - ) + @DtoOperationSaveFile() async usuarioImagemPerfilSave( // @ContextoDeAcessoHttp() contextoDeAcesso: IContextoDeAcesso, diff --git a/luna-backend/src/application/business/ensino/curso/curso.controller.ts b/luna-backend/src/application/business/ensino/curso/curso.controller.ts index 608b5d58..e03bc4d0 100644 --- a/luna-backend/src/application/business/ensino/curso/curso.controller.ts +++ b/luna-backend/src/application/business/ensino/curso/curso.controller.ts @@ -1,6 +1,5 @@ -import { Controller, Delete, Get, Param, ParseUUIDPipe, Patch, Post, Put, UploadedFile, UseInterceptors } from '@nestjs/common'; -import { FileInterceptor } from '@nestjs/platform-express'; -import { ApiBody, ApiConsumes, ApiTags } from '@nestjs/swagger'; +import { Controller, Delete, Get, Param, ParseUUIDPipe, Patch, Post, Put, UploadedFile } from '@nestjs/common'; +import { ApiTags } from '@nestjs/swagger'; import { Paginate, PaginateQuery } from 'nestjs-paginate'; import * as Dto from '../../(spec)'; import { IContextoDeAcesso } from '../../../../domain'; @@ -11,6 +10,7 @@ import { DtoOperationFindAll, DtoOperationFindOne, DtoOperationGetFile, + DtoOperationSaveFile, DtoOperationUpdate, HttpDtoBody, HttpDtoParam, @@ -84,28 +84,7 @@ export class CursoController { } @Put('/:id/imagem/capa') - @ApiConsumes('multipart/form-data') - @ApiBody({ - schema: { - type: 'object', - required: ['file'], - properties: { - file: { - type: 'string', - format: 'binary', - nullable: false, - }, - }, - }, - }) - @UseInterceptors( - FileInterceptor('file', { - limits: { - files: 1, - fileSize: 10 * 1024 * 1024, - }, - }), - ) + @DtoOperationSaveFile() async cursoImagemCapaSave( // @ContextoDeAcessoHttp() contextoDeAcesso: IContextoDeAcesso, diff --git a/luna-backend/src/application/business/ensino/disciplina/disciplina.controller.ts b/luna-backend/src/application/business/ensino/disciplina/disciplina.controller.ts index b51b956f..95c1154d 100644 --- a/luna-backend/src/application/business/ensino/disciplina/disciplina.controller.ts +++ b/luna-backend/src/application/business/ensino/disciplina/disciplina.controller.ts @@ -1,6 +1,5 @@ -import { Controller, Delete, Get, Param, ParseUUIDPipe, Patch, Post, Put, UploadedFile, UseInterceptors } from '@nestjs/common'; -import { FileInterceptor } from '@nestjs/platform-express'; -import { ApiBody, ApiConsumes, ApiTags } from '@nestjs/swagger'; +import { Controller, Delete, Get, Param, ParseUUIDPipe, Patch, Post, Put, UploadedFile } from '@nestjs/common'; +import { ApiTags } from '@nestjs/swagger'; import { Paginate, PaginateQuery } from 'nestjs-paginate'; import * as Dto from '../../(spec)'; import { IContextoDeAcesso } from '../../../../domain'; @@ -11,6 +10,7 @@ import { DtoOperationFindAll, DtoOperationFindOne, DtoOperationGetFile, + DtoOperationSaveFile, DtoOperationUpdate, HttpDtoBody, HttpDtoParam, @@ -84,28 +84,7 @@ export class DisciplinaController { } @Put('/:id/imagem/capa') - @ApiConsumes('multipart/form-data') - @ApiBody({ - schema: { - type: 'object', - required: ['file'], - properties: { - file: { - type: 'string', - format: 'binary', - nullable: false, - }, - }, - }, - }) - @UseInterceptors( - FileInterceptor('file', { - limits: { - files: 1, - fileSize: 10 * 1024 * 1024, - }, - }), - ) + @DtoOperationSaveFile() async disciplinaImagemCapaSave( // @ContextoDeAcessoHttp() contextoDeAcesso: IContextoDeAcesso, diff --git a/luna-backend/src/application/business/ensino/turma/turma.controller.ts b/luna-backend/src/application/business/ensino/turma/turma.controller.ts index 22902758..b5de7936 100644 --- a/luna-backend/src/application/business/ensino/turma/turma.controller.ts +++ b/luna-backend/src/application/business/ensino/turma/turma.controller.ts @@ -1,6 +1,5 @@ -import { Controller, Delete, Get, Param, ParseUUIDPipe, Patch, Post, Put, UploadedFile, UseInterceptors } from '@nestjs/common'; -import { FileInterceptor } from '@nestjs/platform-express'; -import { ApiBody, ApiConsumes, ApiTags } from '@nestjs/swagger'; +import { Controller, Delete, Get, Param, ParseUUIDPipe, Patch, Post, Put, UploadedFile } from '@nestjs/common'; +import { ApiTags } from '@nestjs/swagger'; import { Paginate, PaginateQuery } from 'nestjs-paginate'; import * as Dto from '../../(spec)'; import { IContextoDeAcesso } from '../../../../domain'; @@ -11,6 +10,7 @@ import { DtoOperationFindAll, DtoOperationFindOne, DtoOperationGetFile, + DtoOperationSaveFile, DtoOperationUpdate, HttpDtoBody, HttpDtoParam, @@ -84,28 +84,7 @@ export class TurmaController { } @Put('/:id/imagem/capa') - @ApiConsumes('multipart/form-data') - @ApiBody({ - schema: { - type: 'object', - required: ['file'], - properties: { - file: { - type: 'string', - format: 'binary', - nullable: false, - }, - }, - }, - }) - @UseInterceptors( - FileInterceptor('file', { - limits: { - files: 1, - fileSize: 10 * 1024 * 1024, - }, - }), - ) + @DtoOperationSaveFile() async turmaImagemCapaSave( // @ContextoDeAcessoHttp() contextoDeAcesso: IContextoDeAcesso, diff --git a/luna-backend/src/infrastructure/api-documentate/DtoOperation.ts b/luna-backend/src/infrastructure/api-documentate/DtoOperation.ts index 3fa58a6e..763bef39 100644 --- a/luna-backend/src/infrastructure/api-documentate/DtoOperation.ts +++ b/luna-backend/src/infrastructure/api-documentate/DtoOperation.ts @@ -1,6 +1,7 @@ import { Type, UseInterceptors, applyDecorators } from '@nestjs/common'; import { Mutation, Query, QueryOptions, ReturnTypeFunc } from '@nestjs/graphql'; import { FileInterceptor } from '@nestjs/platform-express'; +import { MulterOptions } from '@nestjs/platform-express/multer/interfaces/multer-options.interface'; import { ApiBearerAuth, ApiBody, ApiConsumes, ApiParam, ApiProduces, ApiQuery, ApiResponse } from '@nestjs/swagger'; import { ReferenceObject, SchemaObject } from '@nestjs/swagger/dist/interfaces/open-api-spec.interface'; import { castArray, has } from 'lodash'; @@ -40,18 +41,23 @@ const responseDeclarationFromDtoOperationSwaggerType = (returnType: IDtoOperatio export type IDtoOperationGqlType = ReturnTypeFunc; -type IMetaGetFile = { +type IDtoOperationOptionsMetaGetFile = { mimeType: string | string[]; }; -type IMeta = { - getFile?: IMetaGetFile; +type IDtoOperationOptionsMetaSaveFile = { + localOptions?: MulterOptions | undefined; +}; + +type IDtoOperationOptionsMeta = { + getFile?: IDtoOperationOptionsMetaGetFile; + saveFile?: IDtoOperationOptionsMetaSaveFile; }; export interface IDtoOperationOptions { description: string; - meta?: IMeta; + meta?: IDtoOperationOptionsMeta; gql: | null @@ -109,7 +115,7 @@ export const createDtoOperationGetFileOptions = (options: Omit { +export const DtoOperationCommon = (options?: IDtoOperationOptions) => { return applyDecorators( ApiBearerAuth(), @@ -118,7 +124,7 @@ export const DtoOperationCommon = (options: IDtoOperationOptions) => { description: 'O solicitante não tem permissão para executar esta ação.', }), - ...(options.swagger.params ?? []).map((param) => + ...(options?.swagger.params ?? []).map((param) => ApiParam({ name: param.name, required: param.required, @@ -126,7 +132,7 @@ export const DtoOperationCommon = (options: IDtoOperationOptions) => { }), ), - ...(options.swagger.queries ?? []).map((query) => { + ...(options?.swagger.queries ?? []).map((query) => { if (typeof query === 'string') { return ApiQuery({ name: query, @@ -202,7 +208,9 @@ export const DtoOperationGetFile = (options: IDtoOperationOptions) => { ); }; -export const DtoOperationSaveFile = (options: IDtoOperationOptions) => { +export const DtoOperationSaveFile = (options?: IDtoOperationOptions) => { + const saveFile = options?.meta?.saveFile; + return applyDecorators( DtoOperationCommon(options), ApiConsumes('multipart/form-data'), @@ -219,14 +227,7 @@ export const DtoOperationSaveFile = (options: IDtoOperationOptions) => { }, }, }), - UseInterceptors( - FileInterceptor('file', { - limits: { - files: 1, - fileSize: 10 * 1024 * 1024, - }, - }), - ), + UseInterceptors(FileInterceptor('file', saveFile?.localOptions)), ); };