mirror of
https://github.com/dadosfera/maestro.git
synced 2026-11-09 21:39:07 +00:00
FEAT: new conection test module
This commit is contained in:
@@ -0,0 +1,18 @@
|
||||
import { Test, TestingModule } from '@nestjs/testing';
|
||||
import { ConnectionTestController } from './connection-test.controller';
|
||||
|
||||
describe('ConnectionTestController', () => {
|
||||
let controller: ConnectionTestController;
|
||||
|
||||
beforeEach(async () => {
|
||||
const module: TestingModule = await Test.createTestingModule({
|
||||
controllers: [ConnectionTestController],
|
||||
}).compile();
|
||||
|
||||
controller = module.get<ConnectionTestController>(ConnectionTestController);
|
||||
});
|
||||
|
||||
it('should be defined', () => {
|
||||
expect(controller).toBeDefined();
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,108 @@
|
||||
import {
|
||||
Body,
|
||||
Controller,
|
||||
HttpCode,
|
||||
HttpStatus,
|
||||
Inject,
|
||||
Post,
|
||||
ValidationPipe,
|
||||
} from '@nestjs/common';
|
||||
import { ApiOkResponse, ApiTags } from '@nestjs/swagger';
|
||||
import { User, RequestUser } from 'src/authentication/user.decorator';
|
||||
import { ConnectionTestService } from './connection-test.service';
|
||||
import {
|
||||
ConnectionTestPingRes,
|
||||
ConnectionTestPingReq,
|
||||
ConnectionTestCredentialsReq,
|
||||
ConnectionTestCredentialsRes,
|
||||
ConnectionTestListSchemasReq,
|
||||
ConnectionTestListSchemasRes,
|
||||
ConnectionTestListTablesReq,
|
||||
ConnectionTestListTablesRes,
|
||||
GetTableMetadataRes,
|
||||
GetTableMetadataReq,
|
||||
} from './dto/connection-test';
|
||||
import { DadosferaLogger } from 'dadosfera-logs';
|
||||
|
||||
@ApiTags('Connection Test')
|
||||
@Controller('connection-test')
|
||||
export class ConnectionTestController {
|
||||
logger: any;
|
||||
constructor(
|
||||
private connectionTestService: ConnectionTestService,
|
||||
@Inject(DadosferaLogger)
|
||||
dadosferaLogger: DadosferaLogger,
|
||||
) {
|
||||
this.logger = dadosferaLogger.logger;
|
||||
}
|
||||
|
||||
@Post('ping')
|
||||
@ApiOkResponse({ type: ConnectionTestPingRes })
|
||||
@HttpCode(HttpStatus.OK)
|
||||
async connectionTestPing(
|
||||
@User() user: RequestUser,
|
||||
@Body(new ValidationPipe()) body: ConnectionTestPingReq,
|
||||
) {
|
||||
this.logger.info('/connection-test/ping', {
|
||||
user: user.user_id,
|
||||
customer: user.customer_name,
|
||||
});
|
||||
await this.connectionTestService.connectionTestPing(body);
|
||||
}
|
||||
|
||||
@Post('credentials')
|
||||
@ApiOkResponse({ type: ConnectionTestCredentialsRes })
|
||||
@HttpCode(HttpStatus.OK)
|
||||
async connectionTestCredentials(
|
||||
@User() user: RequestUser,
|
||||
@Body(new ValidationPipe()) body: ConnectionTestCredentialsReq,
|
||||
) {
|
||||
this.logger.info('/connection-test/credentials', {
|
||||
user: user.user_id,
|
||||
customer: user.customer_name,
|
||||
});
|
||||
await this.connectionTestService.connectionTestCredentials(body);
|
||||
}
|
||||
|
||||
@Post('schemas')
|
||||
@ApiOkResponse({ type: ConnectionTestListSchemasRes })
|
||||
@HttpCode(HttpStatus.OK)
|
||||
async connectionTestListSchemas(
|
||||
@User() user: RequestUser,
|
||||
@Body(new ValidationPipe()) body: ConnectionTestListSchemasReq,
|
||||
) {
|
||||
this.logger.info('/connection-test/schemas', {
|
||||
user: user.user_id,
|
||||
customer: user.customer_name,
|
||||
});
|
||||
await this.connectionTestService.connectionTestListSchemas(body);
|
||||
}
|
||||
|
||||
@Post('tables')
|
||||
@ApiOkResponse({ type: ConnectionTestListTablesRes })
|
||||
@HttpCode(HttpStatus.OK)
|
||||
async connectionTestListTables(
|
||||
@User() user: RequestUser,
|
||||
@Body(new ValidationPipe()) body: ConnectionTestListTablesReq,
|
||||
) {
|
||||
this.logger.info('/connection-test/tables', {
|
||||
user: user.user_id,
|
||||
customer: user.customer_name,
|
||||
});
|
||||
await this.connectionTestService.connectionTestListTables(body);
|
||||
}
|
||||
|
||||
@Post('table-metadata')
|
||||
@ApiOkResponse({ type: GetTableMetadataRes })
|
||||
@HttpCode(HttpStatus.OK)
|
||||
async getTableMetadata(
|
||||
@User() user: RequestUser,
|
||||
@Body(new ValidationPipe()) body: GetTableMetadataReq,
|
||||
) {
|
||||
this.logger.info('/connection-test/tables', {
|
||||
user: user.user_id,
|
||||
customer: user.customer_name,
|
||||
});
|
||||
await this.connectionTestService.getTableMetadata(body);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
import { Module } from '@nestjs/common';
|
||||
import { ConnectionTestController } from './connection-test.controller';
|
||||
import { ConnectionTestService } from './connection-test.service';
|
||||
import { DadosferaLogger } from 'dadosfera-logs';
|
||||
|
||||
@Module({
|
||||
controllers: [ConnectionTestController],
|
||||
providers: [ConnectionTestService, DadosferaLogger],
|
||||
})
|
||||
export class ConnectionTestModule {}
|
||||
@@ -0,0 +1,18 @@
|
||||
import { Test, TestingModule } from '@nestjs/testing';
|
||||
import { ConnectionTestService } from './connection-test.service';
|
||||
|
||||
describe('ConnectionTestService', () => {
|
||||
let service: ConnectionTestService;
|
||||
|
||||
beforeEach(async () => {
|
||||
const module: TestingModule = await Test.createTestingModule({
|
||||
providers: [ConnectionTestService],
|
||||
}).compile();
|
||||
|
||||
service = module.get<ConnectionTestService>(ConnectionTestService);
|
||||
});
|
||||
|
||||
it('should be defined', () => {
|
||||
expect(service).toBeDefined();
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,42 @@
|
||||
import { Injectable } from '@nestjs/common';
|
||||
import {
|
||||
ConnectionTestCredentialsReq,
|
||||
ConnectionTestCredentialsRes,
|
||||
ConnectionTestListSchemasReq,
|
||||
ConnectionTestListSchemasRes,
|
||||
ConnectionTestListTablesReq,
|
||||
ConnectionTestListTablesRes,
|
||||
ConnectionTestPingReq,
|
||||
ConnectionTestPingRes,
|
||||
GetTableMetadataReq,
|
||||
GetTableMetadataRes,
|
||||
} from './dto/connection-test';
|
||||
|
||||
@Injectable()
|
||||
export class ConnectionTestService {
|
||||
async connectionTestPing(
|
||||
body: ConnectionTestPingReq,
|
||||
): Promise<ConnectionTestPingRes> {
|
||||
return { operation_result: true };
|
||||
}
|
||||
async connectionTestCredentials(
|
||||
body: ConnectionTestCredentialsReq,
|
||||
): Promise<ConnectionTestCredentialsRes> {
|
||||
return { operation_result: true, connection_id: '' };
|
||||
}
|
||||
async connectionTestListSchemas(
|
||||
body: ConnectionTestListSchemasReq,
|
||||
): Promise<ConnectionTestListSchemasRes> {
|
||||
return { operation_result: true, schema_list: [] };
|
||||
}
|
||||
async connectionTestListTables(
|
||||
body: ConnectionTestListTablesReq,
|
||||
): Promise<ConnectionTestListTablesRes> {
|
||||
return { operation_result: true, table_list: [] };
|
||||
}
|
||||
async getTableMetadata(
|
||||
body: GetTableMetadataReq,
|
||||
): Promise<GetTableMetadataRes> {
|
||||
return { table_metadata: [{ columns: [], table_name: '' }] };
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,112 @@
|
||||
import { ApiProperty, ApiPropertyOptional, OmitType } from '@nestjs/swagger';
|
||||
import { IsString, IsObject } from 'class-validator';
|
||||
import { DatabaseConnectionPropertiesDto } from 'src/modules/connection/dtos/connection';
|
||||
import { CreateConnectionDto } from 'src/modules/connection/dtos/create-connection';
|
||||
export class ColumnDto {
|
||||
@ApiProperty()
|
||||
name: string;
|
||||
@ApiProperty()
|
||||
type: string;
|
||||
}
|
||||
export class TableMetadataDto {
|
||||
@ApiProperty()
|
||||
table_name: string;
|
||||
@ApiProperty({ type: [ColumnDto] })
|
||||
columns: ColumnDto[];
|
||||
}
|
||||
|
||||
export class ConnectionTestPingReq {
|
||||
@ApiProperty()
|
||||
@IsString()
|
||||
plugin: string;
|
||||
|
||||
@ApiProperty()
|
||||
@IsString()
|
||||
endpoint: string;
|
||||
|
||||
@ApiProperty()
|
||||
@IsString()
|
||||
port: string;
|
||||
|
||||
@ApiPropertyOptional()
|
||||
@IsString()
|
||||
network_config_id?: string;
|
||||
}
|
||||
|
||||
export class ConnectionTestPingRes {
|
||||
@ApiProperty()
|
||||
operation_result: boolean;
|
||||
}
|
||||
|
||||
export class ConnectionTestCredentialsReq extends OmitType(
|
||||
CreateConnectionDto,
|
||||
['properties'],
|
||||
) {
|
||||
@ApiProperty()
|
||||
@IsObject()
|
||||
properties: DatabaseConnectionPropertiesDto;
|
||||
}
|
||||
|
||||
export class ConnectionTestCredentialsRes {
|
||||
@ApiProperty()
|
||||
operation_result: boolean;
|
||||
@ApiProperty()
|
||||
connection_id: string;
|
||||
}
|
||||
|
||||
export class ConnectionTestListSchemasReq {
|
||||
@ApiProperty()
|
||||
@IsString()
|
||||
plugin: string;
|
||||
|
||||
@ApiProperty()
|
||||
@IsString()
|
||||
connection_id: string;
|
||||
}
|
||||
|
||||
export class ConnectionTestListSchemasRes {
|
||||
@ApiProperty()
|
||||
operation_result: boolean;
|
||||
@ApiProperty()
|
||||
schema_list: string[];
|
||||
}
|
||||
|
||||
export class ConnectionTestListTablesReq {
|
||||
@ApiProperty()
|
||||
@IsString()
|
||||
plugin: string;
|
||||
|
||||
@ApiProperty()
|
||||
@IsString()
|
||||
connection_id: string;
|
||||
|
||||
@ApiProperty()
|
||||
@IsString()
|
||||
schema_name: string;
|
||||
}
|
||||
|
||||
export class ConnectionTestListTablesRes {
|
||||
@ApiProperty()
|
||||
operation_result: boolean;
|
||||
@ApiProperty()
|
||||
table_list: string[];
|
||||
}
|
||||
|
||||
export class GetTableMetadataReq {
|
||||
@ApiProperty()
|
||||
@IsString()
|
||||
plugin: string;
|
||||
|
||||
@ApiProperty()
|
||||
@IsString()
|
||||
schema: string;
|
||||
|
||||
@ApiProperty()
|
||||
@IsString()
|
||||
table_list: string[];
|
||||
}
|
||||
|
||||
export class GetTableMetadataRes {
|
||||
@ApiProperty({ type: [TableMetadataDto] })
|
||||
table_metadata: TableMetadataDto[];
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
import { ApiProperty } from '@nestjs/swagger';
|
||||
|
||||
export class DatabaseConnectionPropertiesDto {
|
||||
credentials_type: 'basic_auth';
|
||||
@ApiProperty()
|
||||
plugin: string;
|
||||
@ApiProperty()
|
||||
host: string;
|
||||
@ApiProperty()
|
||||
port: string;
|
||||
@ApiProperty()
|
||||
username: string;
|
||||
@ApiProperty()
|
||||
@ApiProperty()
|
||||
password: string;
|
||||
@ApiProperty()
|
||||
database: string;
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
import { ApiProperty } from '@nestjs/swagger';
|
||||
import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger';
|
||||
import { IsString, IsObject } from 'class-validator';
|
||||
|
||||
export class CreateConnectionDto {
|
||||
@@ -14,9 +14,9 @@ export class CreateConnectionDto {
|
||||
@IsString()
|
||||
description: string;
|
||||
|
||||
@ApiProperty()
|
||||
@ApiPropertyOptional()
|
||||
@IsString()
|
||||
network_config_id: string;
|
||||
network_config_id?: string;
|
||||
|
||||
@ApiProperty()
|
||||
@IsString()
|
||||
|
||||
Reference in New Issue
Block a user