From bf5b3484a1854eeada023d8ec9d421bd0a8c0f57 Mon Sep 17 00:00:00 2001 From: Colombo Date: Tue, 11 Apr 2023 20:39:47 -0300 Subject: [PATCH] FEAT: add controller method interfaces --- docsfera.json | 43 +++++++++++++++++-- src/modules/customers/customers.controller.ts | 15 ++++--- src/modules/customers/dtos/customers.ts | 12 ++++++ 3 files changed, 60 insertions(+), 10 deletions(-) create mode 100644 src/modules/customers/dtos/customers.ts diff --git a/docsfera.json b/docsfera.json index 113884b..054c67e 100644 --- a/docsfera.json +++ b/docsfera.json @@ -4710,10 +4710,7 @@ "content": { "application/json": { "schema": { - "type": "array", - "items": { - "type": "object" - } + "$ref": "#/components/schemas/CustomerLinksResponse" } } } @@ -4734,6 +4731,16 @@ "put": { "operationId": "CustomersController_setCustomerLinks", "parameters": [], + "requestBody": { + "required": true, + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/CustomerDto" + } + } + } + }, "responses": { "200": { "description": "", @@ -7455,6 +7462,34 @@ "content", "tags" ] + }, + "CustomerLinksResponse": { + "type": "object", + "properties": { + "links": { + "type": "array", + "items": { + "type": "string" + } + } + }, + "required": [ + "links" + ] + }, + "CustomerDto": { + "type": "object", + "properties": { + "links": { + "type": "array", + "items": { + "type": "string" + } + } + }, + "required": [ + "links" + ] } } } diff --git a/src/modules/customers/customers.controller.ts b/src/modules/customers/customers.controller.ts index e2b06f7..e69d331 100644 --- a/src/modules/customers/customers.controller.ts +++ b/src/modules/customers/customers.controller.ts @@ -1,5 +1,5 @@ import { DadosferaLogger } from '@dadosfera/dadosfera-logs'; -import { Link } from '@dadosfera/protospack-v2/dist/lib/Duc/interfaces/entities'; +import { IdResponse } from '@dadosfera/protospack-v2/dist/lib/Duc/interfaces/messages'; import { Body, Controller, @@ -18,6 +18,7 @@ import { import { ApiInternalOnlyController } from 'src/decorators/swagger.decorator'; import { GrpcToHttpExceptionFilter } from 'src/error/grpc-to-http-exception.filter'; import { CustomersService } from './customers.service'; +import { CustomerDto, CustomerLinksResponse } from './dtos/customers'; @ApiInternalOnlyController() @ApiTags('Customers') @@ -37,16 +38,18 @@ export class CustomersController { @Get(':id/links') @RequireAllPermissions(PERMISSIONS_GROUPS.USERS.permissions.ADMIN) - getCustomerLinks(@Param() params): Promise { - const { id } = params; + async getCustomerLinks(@Param('id') id): Promise { this.logger.info('getCustomerLinks', { id }); - return this.customersService.getLinks(id); + const links = await this.customersService.getLinks(id); + return { links }; } @Put(':id/links') @RequireAllPermissions(PERMISSIONS_GROUPS.USERS.permissions.ADMIN) - setCustomerLinks(@Body() body, @Param() params) { - const { id } = params; + setCustomerLinks( + @Body() body: CustomerDto, + @Param('id') id, + ): Promise { const { links } = body; this.logger.info('setCustomerLinks', { id, links }); return this.customersService.setLinks(id, links); diff --git a/src/modules/customers/dtos/customers.ts b/src/modules/customers/dtos/customers.ts new file mode 100644 index 0000000..01337ad --- /dev/null +++ b/src/modules/customers/dtos/customers.ts @@ -0,0 +1,12 @@ +import { Link } from '@dadosfera/protospack-v2/dist/lib/Duc/interfaces/entities'; +import { ApiProperty } from '@nestjs/swagger'; + +export class CustomerDto { + @ApiProperty() + links: Link[]; +} + +export class CustomerLinksResponse { + @ApiProperty() + links: Link[]; +}