diff --git a/package-lock.json b/package-lock.json index 4b21786..5bbab1f 100644 --- a/package-lock.json +++ b/package-lock.json @@ -11,7 +11,7 @@ "dependencies": { "@aws-sdk/client-secrets-manager": "^3.112.0", "@dadosfera/dadosfera-logs": "^1.0.0-beta.3", - "@dadosfera/protospack-v2": "3.11.2", + "@dadosfera/protospack-v2": "3.11.3", "@grpc/grpc-js": "^1.6.7", "@grpc/proto-loader": "^0.6.13", "@nestjs/common": "^8.4.7", @@ -1725,9 +1725,9 @@ } }, "node_modules/@dadosfera/protospack-v2": { - "version": "3.11.2", - "resolved": "https://dadosfera-611330257153.d.codeartifact.us-east-1.amazonaws.com:443/npm/dadosfera-npm/@dadosfera/protospack-v2/-/protospack-v2-3.11.2.tgz", - "integrity": "sha512-Lwrf/AvkxkWXDmFLhlneXPedTkHeKZz4hCyT11Q9UiyAEl3hdqKzSnXOwSLbSpqbG3XD6GmIundgQtvf72k1Eg==", + "version": "3.11.3", + "resolved": "https://dadosfera-611330257153.d.codeartifact.us-east-1.amazonaws.com:443/npm/dadosfera-npm/@dadosfera/protospack-v2/-/protospack-v2-3.11.3.tgz", + "integrity": "sha512-gcAd3TeEfNH3ZVN/H9vct8T5NEnGAZpunnW/x/fRwEyJ8EMizRjxN7drAUXpabfMY0K33BnbDCbBKAuiHADqRA==", "dependencies": { "@grpc/grpc-js": "^1.6.7", "rxjs": "^7.5.5", @@ -12283,9 +12283,9 @@ } }, "@dadosfera/protospack-v2": { - "version": "3.11.2", - "resolved": "https://dadosfera-611330257153.d.codeartifact.us-east-1.amazonaws.com:443/npm/dadosfera-npm/@dadosfera/protospack-v2/-/protospack-v2-3.11.2.tgz", - "integrity": "sha512-Lwrf/AvkxkWXDmFLhlneXPedTkHeKZz4hCyT11Q9UiyAEl3hdqKzSnXOwSLbSpqbG3XD6GmIundgQtvf72k1Eg==", + "version": "3.11.3", + "resolved": "https://dadosfera-611330257153.d.codeartifact.us-east-1.amazonaws.com:443/npm/dadosfera-npm/@dadosfera/protospack-v2/-/protospack-v2-3.11.3.tgz", + "integrity": "sha512-gcAd3TeEfNH3ZVN/H9vct8T5NEnGAZpunnW/x/fRwEyJ8EMizRjxN7drAUXpabfMY0K33BnbDCbBKAuiHADqRA==", "requires": { "@grpc/grpc-js": "^1.6.7", "rxjs": "^7.5.5", diff --git a/package.json b/package.json index 0dddc3c..640915b 100644 --- a/package.json +++ b/package.json @@ -53,7 +53,7 @@ "passport-hubspot-oauth2": "^1.0.3", "passport-mailchimp": "^1.1.0", "protospack": "2.5.2", - "@dadosfera/protospack-v2": "3.11.2", + "@dadosfera/protospack-v2": "3.11.3", "reflect-metadata": "^0.1.13", "rimraf": "^3.0.2", "rxjs": "^7.5.5", diff --git a/src/modules/connection-test/connection-test.service.ts b/src/modules/connection-test/connection-test.service.ts index e6fee03..9815591 100644 --- a/src/modules/connection-test/connection-test.service.ts +++ b/src/modules/connection-test/connection-test.service.ts @@ -62,10 +62,10 @@ export class ConnectionTestService { const createConnectionBody: CreateConnectionDto = { ...body, }; - const { connection } = await this.connectionsService.createConnection({ - body: createConnectionBody, - info: { customer_id, customer_name, user_id }, - }); + const { connection } = await this.connectionsService.createConnection( + createConnectionBody, + { customer_id, customer_name, user_id }, + ); connection_id = connection.id; } /************************************/ diff --git a/src/modules/connection/client.service.ts b/src/modules/connection/client.service.ts index 10f6c97..b192c5f 100644 --- a/src/modules/connection/client.service.ts +++ b/src/modules/connection/client.service.ts @@ -8,8 +8,14 @@ import { import { ClientGrpc } from '@nestjs/microservices'; import { ConnectionManager } from '@dadosfera/protospack-v2'; import { lastValueFrom } from 'rxjs'; -import { GetConnectionsRes } from './dtos/connection'; +import { + ConnectionRes, + ConnectionsRes, + CreateConnectionDto, + UpdateConnectionDto, +} from './dtos/connection'; import { ConnectionClientConfiguration } from './client.config'; +import { GetConnectionDetailsResponse } from '@dadosfera/protospack-v2/dist/lib/ConnectionManager/interfaces/messages'; export class ConnectionClientService implements OnModuleInit { private connectionServiceRead: ConnectionManager.ReadService.ConnectionManagerReadServices; @@ -31,7 +37,10 @@ export class ConnectionClientService implements OnModuleInit { ); } - async createConnection({ body, info }) { + async createConnection( + body: CreateConnectionDto, + info: any, + ): Promise { const meta = new Metadata(); meta.add('customer_id', info.customer_id); meta.add('customer_name', info.customer_name); @@ -70,33 +79,27 @@ export class ConnectionClientService implements OnModuleInit { }); } - async updateConnection({ body, info }) { + async updateConnection( + id: string, + body: UpdateConnectionDto, + info, + ): Promise { const meta = new Metadata(); meta.add('customer_id', info.customer_id); meta.add('customer_name', info.customer_name); meta.add('user_id', info.user_id); meta.add('language', info.language); - const { - id, - description, - image_url, - name, - network_config_id, - properties, - type, - } = body; + const { description, name, network_config_id, properties } = body; return lastValueFrom( this.connectionServiceWrite.UpdateConnection( { id, description, - image_url, name, network_config_id, properties: JSON.stringify(properties), - type, }, meta, ), @@ -108,7 +111,7 @@ export class ConnectionClientService implements OnModuleInit { }); } - async deleteConnection({ body, info }) { + async deleteConnection({ body, info }): Promise { const meta = new Metadata(); meta.add('customer_id', info.customer_id); meta.add('customer_name', info.customer_name); @@ -131,7 +134,7 @@ export class ConnectionClientService implements OnModuleInit { }); } - async getAllConnection({ body, info }): Promise { + async getAllConnection({ body, info }): Promise { const meta = new Metadata(); meta.add('customer_id', info.customer_id); meta.add('customer_name', info.customer_name); @@ -153,7 +156,7 @@ export class ConnectionClientService implements OnModuleInit { }); } - async getConnection({ body, info }) { + async getConnection({ body, info }): Promise { const meta = new Metadata(); meta.add('customer_id', info.customer_id); meta.add('customer_name', info.customer_name); @@ -172,7 +175,10 @@ export class ConnectionClientService implements OnModuleInit { }); } - async getConnectionDetails({ body, info }) { + async getConnectionDetails({ + body, + info, + }): Promise { const meta = new Metadata(); meta.add('customer_id', info.customer_id); meta.add('customer_name', info.customer_name); diff --git a/src/modules/connection/connection.controller.ts b/src/modules/connection/connection.controller.ts index adfd946..6d94d87 100644 --- a/src/modules/connection/connection.controller.ts +++ b/src/modules/connection/connection.controller.ts @@ -20,7 +20,12 @@ import { import { PERMISSIONS } from 'src/authentication/permissions.enum'; import { User } from 'src/authentication/user.decorator'; import { ValidationPipe } from '../../pipes/object-validation.pipe'; -import { GetConnectionsRes, UpdateConnectionDto } from './dtos/connection'; +import { + ConnectionDetailsRes, + ConnectionRes, + ConnectionsRes, + UpdateConnectionDto, +} from './dtos/connection'; import { CreateConnectionDto } from './dtos/connection'; @ApiTags('connections') @@ -42,14 +47,15 @@ export class ConnectionController { async createConnection( @User() user, @Body(new ValidationPipe()) body: CreateConnectionDto, - ) { + ): Promise { this.logger.info('/connections - Create Connection'); const { user_id, customer_id, customer_name } = user; - const response: any = await this.clientService.createConnection({ - body, - info: { user_id, customer_id, customer_name }, + const response: any = await this.clientService.createConnection(body, { + user_id, + customer_id, + customer_name, }); return response; @@ -59,17 +65,19 @@ export class ConnectionController { // @RequireAllPermissions(Permissions.CONNECTIONS.CREATE) async updateConnection( @User() user, - @Headers('Dadosfera-Lang') language, - @Param('id') id, + @Headers('Dadosfera-Lang') language: string, + @Param('id') id: string, @Body(new ValidationPipe()) body: UpdateConnectionDto, - ) { + ): Promise { this.logger.info('/connections - Update Connection'); const { user_id, customer_id, customer_name } = user; - const response: any = await this.clientService.updateConnection({ - body: { ...body, id }, - info: { user_id, customer_id, customer_name, language }, + const response: any = await this.clientService.updateConnection(id, body, { + user_id, + customer_id, + customer_name, + language, }); return response; @@ -77,7 +85,10 @@ export class ConnectionController { @Delete('/:id') // @RequireAllPermissions(Permissions.CONNECTIONS.CREATE) - async deleteConnection(@User() user, @Param('id') id) { + async deleteConnection( + @User() user, + @Param('id') id: string, + ): Promise { this.logger.info('/connections - Delete Connection'); const { user_id, customer_id, customer_name } = user; @@ -96,7 +107,7 @@ export class ConnectionController { @User() user, @Headers('Dadosfera-Lang') language, @Query() queries, - ): Promise { + ): Promise { this.logger.info('/connections - Get All Connection'); const { user_id, customer_id, customer_name } = user; @@ -116,7 +127,7 @@ export class ConnectionController { @User() user, @Headers('Dadosfera-Lang') language, @Param('id') id, - ) { + ): Promise { this.logger.info('/connections - Get Connection'); const { user_id, customer_id, customer_name } = user; @@ -131,7 +142,10 @@ export class ConnectionController { @Get('/:id/details') // @RequireAllPermissions(Permissions.CONNECTIONS.CREATE) - async getConnectionDetails(@User() user, @Param('id') id) { + async getConnectionDetails( + @User() user, + @Param('id') id, + ): Promise { this.logger.info('/connections - Get Connection Details'); const { user_id, customer_id, customer_name } = user; diff --git a/src/modules/connection/dtos/connection.ts b/src/modules/connection/dtos/connection.ts index 1372cfc..8a42e5a 100644 --- a/src/modules/connection/dtos/connection.ts +++ b/src/modules/connection/dtos/connection.ts @@ -8,7 +8,11 @@ import { Connection, ConnectionToCatalog, } from '@dadosfera/protospack-v2/dist/lib/ConnectionManager/interfaces/entities'; -import { GetAllConnectionResponse } from '@dadosfera/protospack-v2/dist/lib/ConnectionManager/interfaces/messages'; +import { + GetAllConnectionResponse, + GetConnectionDetailsResponse, + GetConnectionResponse, +} from '@dadosfera/protospack-v2/dist/lib/ConnectionManager/interfaces/messages'; export class ConnectionDto implements Connection { // ---Automatically generated information will not be sent by the frontend--- // @@ -82,15 +86,32 @@ export class UpdateConnectionDto extends PickType(ConnectionDto, [ 'properties', ]) {} -export class GetConnectionsRes implements GetAllConnectionResponse { +export class ConnectionsRes implements GetAllConnectionResponse { @ApiProperty() - connections: Connection[]; + connections: ConnectionToCatalog[]; + + @ApiProperty() + message: string; +} + +export class ConnectionRes implements GetConnectionResponse { + @ApiProperty() + connection?: ConnectionToCatalog; + + @ApiProperty() + message: string; +} + +export class ConnectionDetailsRes implements GetConnectionDetailsResponse { + @ApiProperty() + connection?: Connection; @ApiProperty() message: string; } export class DatabaseConnectionPropertiesDto { + @ApiProperty() credentials_type: 'basic_auth'; @ApiProperty() plugin: string;