From 55b0961b82bb18a04465d7d81774f4572fede40d Mon Sep 17 00:00:00 2001 From: viniciusgadea Date: Fri, 2 Jan 2026 09:21:46 -0300 Subject: [PATCH] FEAT: add organization info endpoints and DTOs for update and retrieval new organization forms --- package.json | 2 +- src/modules/customers/customers.controller.ts | 28 ++++++++++ src/modules/customers/customers.service.ts | 55 ++++++++++++++++++- src/modules/customers/dtos/organization.ts | 27 +++++++++ 4 files changed, 110 insertions(+), 2 deletions(-) create mode 100644 src/modules/customers/dtos/organization.ts diff --git a/package.json b/package.json index 2a2c4b8..575634b 100644 --- a/package.json +++ b/package.json @@ -35,7 +35,7 @@ "@aws-sdk/signature-v4": "^3.370.0", "@dadosfera/dadosfera-logs": "^1.0.0-beta.4", "@dadosfera/protospack": "2.5.3", - "@dadosfera/protospack-v2": "3.38.0-beta.19", + "@dadosfera/protospack-v2": "^3.38.0-beta.23", "@grpc/grpc-js": "^1.9.3", "@grpc/proto-loader": "^0.7.9", "@nestjs/cli": "^9.5.0", diff --git a/src/modules/customers/customers.controller.ts b/src/modules/customers/customers.controller.ts index 2606ebd..b3f6c37 100644 --- a/src/modules/customers/customers.controller.ts +++ b/src/modules/customers/customers.controller.ts @@ -136,4 +136,32 @@ export class CustomersController { const result = await this.customersService.getAccessDashboardUrl(user.customer_name, metadata); return result; } + + @Get(':id/organization-info') + @Authenticated() + @RequireAllPermissions(PERMISSIONS_GROUPS.USERS.permissions.ADMIN) + @ApiOkResponse({ description: 'Organization information' }) + async getOrganizationInfo(@Param('id') id: string) { + this.logger.info('getOrganizationInfo', { id }); + return this.customersService.getOrganizationInfo(id); + } + + @Put(':id/organization-info') + @Authenticated() + @RequireAllPermissions(PERMISSIONS_GROUPS.USERS.permissions.ADMIN) + @HttpCode(HttpStatus.OK) + @ApiOkResponse({ description: 'Organization information updated' }) + async updateOrganizationInfo( + @Param('id') id: string, + @Body() body: { + name: string; + companySite: string; + domain: string; + cnpj: string; + description: string; + }, + ) { + return this.customersService.updateOrganizationInfo(id, body); + } + } diff --git a/src/modules/customers/customers.service.ts b/src/modules/customers/customers.service.ts index 8b28171..92b18ea 100644 --- a/src/modules/customers/customers.service.ts +++ b/src/modules/customers/customers.service.ts @@ -223,4 +223,57 @@ export class CustomersService implements OnModuleInit { }) ) } -} + + async updateOrganizationInfo( + customerId: string, + data: { + name: string; + companySite: string; + domain: string; + cnpj: string; + description: string; + }, + ) { + try { + const result = await lastValueFrom( + this.customerService.OrganizationUpdate({ + customerId, + name: data.name || '', + companySite: data.companySite || '', + domain: data.domain || '', + cnpj: data.cnpj || '', + description: data.description || '', + }), + ); + + return result; + } catch (err) { + if (err.details === ErrorCodes.CUSTOMER.NOT_FOUND) + throw new HttpException(err.details, HttpStatus.NOT_FOUND); + else throw err; + } + } + + async getOrganizationInfo(customerId: string) { + try { + const customerResponse = await lastValueFrom( + this.customerService.CustomerFindOneById({ id: customerId }) + ); + + const customer = customerResponse.customer; + + return { + name: customer.name || '', + companySite: customer.companySite || '', + domain: customer.domain || '', + cnpj: customer.cnpj || '', + description: customer.description || '' + }; + } catch (err) { + if (err.details === ErrorCodes.CUSTOMER.NOT_FOUND) + throw new HttpException(err.details, HttpStatus.NOT_FOUND); + else throw err; + } + } + +} \ No newline at end of file diff --git a/src/modules/customers/dtos/organization.ts b/src/modules/customers/dtos/organization.ts new file mode 100644 index 0000000..50c3df7 --- /dev/null +++ b/src/modules/customers/dtos/organization.ts @@ -0,0 +1,27 @@ +import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger'; + +export class OrganizationUpdateRequest { + @ApiProperty() + name: string; + @ApiPropertyOptional() + companySite: string; + @ApiProperty() + domain: string; + @ApiPropertyOptional() + info: string; + @ApiPropertyOptional() + cnpj: string; +} + +export class OrganizationResponse { + @ApiProperty() + name: string; + @ApiPropertyOptional() + companySite: string; + @ApiProperty() + domain: string; + @ApiPropertyOptional() + info: string; + @ApiPropertyOptional() + cnpj: string; +} \ No newline at end of file