Update feature

This commit is contained in:
Victor Radael
2022-08-12 10:38:20 -03:00
parent 7c5cf3f541
commit acd4dafc57
12 changed files with 229 additions and 177 deletions
@@ -15,7 +15,7 @@ import {
GetTableMetadataRes,
} from './dto/connection-test';
import { ConnectionClientService } from '../connection/client.service';
import { CreateConnectionDto } from '../connection/dtos/create-connection';
import { CreateConnectionDto } from '../connection/dtos/connection';
import { RequestUser } from 'src/authentication/user.decorator';
@Injectable()
@@ -60,7 +60,7 @@ export class ConnectionTestService {
connectionBody.properties.credentials_type = 'basic_auth';
const createConnectionBody: CreateConnectionDto = {
...connectionBody,
...body,
};
const { connection } = await this.connectionsService.createConnection({
body: createConnectionBody,
@@ -1,7 +1,7 @@
import { ApiProperty, ApiPropertyOptional, OmitType } from '@nestjs/swagger';
import { IsString, IsOptional } from 'class-validator';
import { DatabaseConnectionPropertiesDto } from 'src/modules/connection/dtos/connection';
import { CreateConnectionDto } from 'src/modules/connection/dtos/create-connection';
import { CreateConnectionDto } from 'src/modules/connection/dtos/connection';
export class ColumnDto {
@ApiProperty()
name: string;
+4 -1
View File
@@ -8,6 +8,7 @@ import {
import { ClientGrpc } from '@nestjs/microservices';
import { ConnectionManager } from '@dadosfera/protospack-v2';
import { lastValueFrom } from 'rxjs';
import { GetConnectionsRes } from './dtos/connection';
export class ConnectionClientService implements OnModuleInit {
private connectionServiceRead: ConnectionManager.ReadService.ConnectionManagerReadServices;
@@ -42,12 +43,14 @@ export class ConnectionClientService implements OnModuleInit {
network_config_id,
properties,
type,
connector_name,
} = body;
return lastValueFrom(
this.connectionServiceWrite.CreateConnection(
{
connector_id,
connector_name,
description,
image_url,
name,
@@ -126,7 +129,7 @@ export class ConnectionClientService implements OnModuleInit {
});
}
async getAllConnection({ body, info }) {
async getAllConnection({ body, info }): Promise<GetConnectionsRes> {
const meta = new Metadata();
meta.add('customer_id', info.customer_id);
meta.add('customer_name', info.customer_name);
@@ -12,7 +12,6 @@ import {
} from '@nestjs/common';
import { ApiBearerAuth, ApiTags } from '@nestjs/swagger';
import { ConnectionClientService } from './client.service';
import { CreateConnectionDto } from './dtos/create-connection';
import { DadosferaLogger } from '@dadosfera/dadosfera-logs';
import {
Authenticated,
@@ -21,8 +20,8 @@ import {
import { PERMISSIONS } from 'src/authentication/permissions.enum';
import { User } from 'src/authentication/user.decorator';
import { ValidationPipe } from '../../pipes/object-validation.pipe';
import { UpdateConnectionDto } from './dtos/update-connection';
import { identity } from 'rxjs';
import { GetConnectionsRes, UpdateConnectionDto } from './dtos/connection';
import { CreateConnectionDto } from './dtos/connection';
@ApiTags('connections')
@ApiBearerAuth()
@@ -53,12 +52,6 @@ export class ConnectionController {
info: { user_id, customer_id, customer_name },
});
delete response.connection.properties;
delete response.connection.user_id;
delete response.connection.customer_id;
delete response.connection.customer_name;
delete response.connection.updated_at;
return response;
}
@@ -79,12 +72,6 @@ export class ConnectionController {
info: { user_id, customer_id, customer_name, language },
});
delete response.connection.properties;
delete response.connection.user_id;
delete response.connection.customer_id;
delete response.connection.customer_name;
delete response.connection.updated_at;
return response;
}
@@ -100,12 +87,6 @@ export class ConnectionController {
info: { user_id, customer_id, customer_name },
});
delete response.connection.properties;
delete response.connection.user_id;
delete response.connection.customer_id;
delete response.connection.customer_name;
delete response.connection.updated_at;
return response;
}
@@ -115,7 +96,7 @@ export class ConnectionController {
@User() user,
@Headers('Dadosfera-Lang') language,
@Query() queries,
) {
): Promise<GetConnectionsRes> {
this.logger.info('/connections - Get All Connection');
const { user_id, customer_id, customer_name } = user;
@@ -145,11 +126,6 @@ export class ConnectionController {
info: { user_id, customer_id, customer_name, language },
});
delete response.connection.user_id;
delete response.connection.customer_id;
delete response.connection.customer_name;
delete response.connection.updated_at;
return response;
}
+91 -2
View File
@@ -1,4 +1,94 @@
import { ApiProperty } from '@nestjs/swagger';
import {
ApiProperty,
ApiPropertyOptional,
OmitType,
PickType,
} from '@nestjs/swagger';
import {
Connection,
ConnectionToCatalog,
} from '@dadosfera/protospack-v2/dist/lib/ConnectionManager/interfaces/entities';
import { GetAllConnectionResponse } from '@dadosfera/protospack-v2/dist/lib/ConnectionManager/interfaces/messages';
export class ConnectionDto implements Connection {
// ---Automatically generated information will not be sent by the frontend--- //
@ApiProperty()
id: string;
@ApiProperty()
customer_id: string;
@ApiProperty()
customer_name: string;
@ApiProperty()
user_id: string;
@ApiProperty()
updated_at: string;
@ApiProperty()
created_at: string;
@ApiProperty()
pipelines: string;
// ---Information sent by the frontend--- //
@ApiProperty()
name: string;
@ApiProperty()
description: string;
@ApiProperty()
type: string;
@ApiPropertyOptional()
network_config_id: string | null;
@ApiProperty()
properties: any | DatabaseConnectionPropertiesDto;
// ---Information sent by the frontend (Heirs of Connector)--- //
@ApiProperty()
connector_id: string;
@ApiProperty()
connector_name: string;
@ApiProperty()
plugin: string;
@ApiProperty()
image_url: string;
}
export class CreateConnectionDto extends OmitType(ConnectionDto, [
'id',
'customer_id',
'customer_name',
'user_id',
'created_at',
'updated_at',
'pipelines',
]) {}
export class UpdateConnectionDto extends PickType(ConnectionDto, [
'name',
'description',
'network_config_id',
'properties',
]) {}
export class GetConnectionsRes implements GetAllConnectionResponse {
@ApiProperty()
connections: Connection[];
@ApiProperty()
message: string;
}
export class DatabaseConnectionPropertiesDto {
credentials_type: 'basic_auth';
@@ -11,7 +101,6 @@ export class DatabaseConnectionPropertiesDto {
@ApiProperty()
username: string;
@ApiProperty()
@ApiProperty()
password: string;
@ApiProperty()
database: string;
@@ -1,33 +0,0 @@
import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger';
import { IsString, IsObject, IsOptional } from 'class-validator';
export class CreateConnectionDto {
@ApiProperty()
@IsString()
connector_id: string;
@ApiProperty()
@IsString()
name: string;
@ApiProperty()
@IsString()
description: string;
@ApiPropertyOptional()
@IsString()
@IsOptional()
network_config_id?: string | null;
@ApiProperty()
@IsString()
type: string;
@ApiProperty()
@IsString()
image_url: string;
@ApiProperty()
@IsObject()
properties: any;
}
@@ -1,24 +0,0 @@
import { ApiProperty } from '@nestjs/swagger';
import { IsString, IsObject, IsOptional } from 'class-validator';
export class UpdateConnectionDto {
@ApiProperty()
@IsString()
@IsOptional()
name: string;
@ApiProperty()
@IsString()
@IsOptional()
description: string;
@ApiProperty()
@IsString()
@IsOptional()
network_config_id: string;
@ApiProperty()
@IsObject()
@IsOptional()
properties: any;
}
+7 -4
View File
@@ -25,6 +25,7 @@ import {
TestConnectionReq,
TestConnectionRes,
} from './dtos/input.model';
import { User } from 'src/authentication/user.decorator';
@ApiTags('inputs')
@Controller('inputs')
@@ -134,13 +135,15 @@ export class InputsController {
}
@Get()
async findAll(@Body() body) {
async findAll(@User() user, @Body() body) {
this.logger.info(`/input - ON FIND ALL ROUTE`, {
user: body.info.user_id,
customer: body.info.customer,
user: user.user_id,
customer: user.customer_id,
});
const response = await this.inputService.findAll(body);
const response = await this.inputService.findAll({
info: { user: user.user_id, customer: user.customer_id },
});
return response;
}
@@ -1,3 +1,4 @@
import { NetworkConfigEntity } from '@dadosfera/protospack-v2/dist/lib/NetworkConfig/interfaces/entities';
import {
ApiProperty,
ApiPropertyOptional,
@@ -11,12 +12,10 @@ export enum NetworkConfigTypesEnum {
export enum NetworkConfigPluginsEnum {
openvpn = 'openvpn',
}
export class NetworkConfigDto {
export class NetworkConfigDto implements NetworkConfigEntity {
@ApiProperty()
id: string;
@ApiProperty()
secret_id: string;
@ApiProperty()
name: string;
@ApiProperty()
customer_name: string;
@@ -27,17 +26,26 @@ export class NetworkConfigDto {
@ApiProperty({ enum: NetworkConfigPluginsEnum })
plugin: string;
@ApiProperty()
credentials: any;
properties: any;
@ApiProperty()
created_at: string;
@ApiProperty()
updated_at: string;
@ApiProperty()
network_type_id: string;
@ApiProperty()
network_type_name: string;
@ApiProperty()
user_id: string;
@ApiProperty()
customer_id: string;
@ApiProperty()
keywords: string;
@ApiProperty()
tags: string;
}
export class NetworkConfigNoSecrets extends OmitType(NetworkConfigDto, [
'secret_id',
'credentials',
'properties',
]) {}
export class NetworkConfigOpenVpnProperties {
@ApiProperty({ enum: NetworkConfigPluginsEnum })
@@ -15,9 +15,9 @@ export class NetworkConfigClientConfiguration {
NetworkConfig.ProtoPackages.ReadPackage,
NetworkConfig.ProtoPackages.WritePackage,
],
// credentials: undefined,
credentials:
process.env.ENV === 'local' ? undefined : credentials.createSsl(),
credentials: undefined,
// credentials:
// process.env.ENV === 'local' ? undefined : credentials.createSsl(),
protoPath: [
NetworkConfig.ProtoPaths.ReadFilePath,
NetworkConfig.ProtoPaths.WriteFilePath,