Connected Connection Test routes to microservice

This commit is contained in:
Gabriel Rosa
2022-07-27 14:19:25 -03:00
parent 54c2a41466
commit d28684a9d0
7 changed files with 142 additions and 23 deletions
@@ -1,4 +1,7 @@
import { Injectable } from '@nestjs/common';
import { Inject, Injectable } from '@nestjs/common';
import { ClientGrpc } from '@nestjs/microservices';
import { ConnectionTest } from 'protospack-v2';
import { lastValueFrom } from 'rxjs';
import {
ConnectionTestCredentialsReq,
ConnectionTestCredentialsRes,
@@ -14,29 +17,89 @@ import {
@Injectable()
export class ConnectionTestService {
private connectionTestReadClient: ConnectionTest.ReadService.ConnectionTestReadServices;
constructor(
@Inject('ConnectionTestGrpcClient') private readonly grpcClient: ClientGrpc,
) {
this.connectionTestReadClient =
grpcClient.getService<ConnectionTest.ReadService.ConnectionTestReadServices>(
ConnectionTest.ProtoServices.ConnectionTestReadServices,
);
}
async connectionTestPing(
body: ConnectionTestPingReq,
customer_name: string,
): Promise<ConnectionTestPingRes> {
return { operation_result: true };
const { endpoint, plugin, port, network_config_id } = body;
return lastValueFrom(
this.connectionTestReadClient.ConnectionTestPing({
customer_name,
endpoint,
network_config_id,
plugin,
port,
}),
);
}
async connectionTestCredentials(
body: ConnectionTestCredentialsReq,
customer_name: string,
): Promise<ConnectionTestCredentialsRes> {
return { operation_result: true, connection_id: '' };
const { connector_id, plugin } = body;
//CREATE CONNECTION
const connection_id = '';
/***********************/
const { operation_result } = await lastValueFrom(
this.connectionTestReadClient.ConnectionTestCredentials({
connection_id,
customer_name,
plugin,
}),
);
return { operation_result, connection_id };
}
async connectionTestListSchemas(
body: ConnectionTestListSchemasReq,
customer_name: string,
): Promise<ConnectionTestListSchemasRes> {
return { operation_result: true, schema_list: [] };
const { connection_id, plugin } = body;
return lastValueFrom(
this.connectionTestReadClient.ListSchemas({
connection_id,
customer_name,
plugin,
}),
);
}
async connectionTestListTables(
body: ConnectionTestListTablesReq,
customer_name: string,
): Promise<ConnectionTestListTablesRes> {
return { operation_result: true, table_list: [] };
const { connection_id, plugin, schema } = body;
return lastValueFrom(
this.connectionTestReadClient.ListTables({
connection_id,
customer_name,
plugin,
schema,
}),
);
}
async getTableMetadata(
body: GetTableMetadataReq,
customer_name: string,
): Promise<GetTableMetadataRes> {
return { table_metadata: [{ columns: [], table_name: '' }] };
const { schema, plugin, table_list, connection_id } = body;
return lastValueFrom(
this.connectionTestReadClient.GetTableMetadata({
connection_id,
customer_name,
plugin,
schema,
table_list,
}),
);
}
}