maestro connection with microservices - clients and modules

This commit is contained in:
rodrigo.zamboni
2022-03-18 10:16:27 -03:00
parent e15a680b9f
commit 1523c6b4d1
25 changed files with 1668 additions and 639 deletions
+1
View File
@@ -0,0 +1 @@
//registry.npmjs.org/:_authToken=${NPM_TOKEN}
+1 -1
View File
@@ -30,7 +30,7 @@
"@nestjs/microservices": "^8.4.0",
"@nestjs/platform-express": "^8.4.0",
"@nestjs/swagger": "^5.1.5",
"@victorradael/protospack": "^1.1.3",
"@victorradael/protospack": "^1.2.8",
"axios": "^0.25.0",
"dotenv": "^14.2.0",
"grpc": "^1.24.11",
+42 -33
View File
@@ -4,39 +4,44 @@ import { ConfigModule } from '@nestjs/config';
import { LoggerMiddleware } from './middlewares/authentication';
// import { InputsController } from './modules/inputs/inputs.controller';
// import { TransformationsController } from './modules/transformations/transformations.controller';
// import { OutputsController } from './modules/outputs/outputs.controllers';
// import { PipelinesController } from './modules/pipelines/pipelines.controller';
import { InputsController } from './modules/inputs/inputs.controller';
import { TransformationsController } from './modules/transformations/transformations.controller';
import { OutputsController } from './modules/outputs/outputs.controllers';
import { PipelinesController } from './modules/pipelines/pipelines.controller';
import { AuthController } from './modules/auth/auth.controller';
import { HealthController } from './modules/health/health.controller';
import { InputsService } from './modules/inputs/inputs.service';
import { TransformationsService } from './modules/transformations/transformations.service';
import { OutputsService } from './modules/outputs/outputs.service';
// import { PipelinesService } from './modules/pipelines/pipelines.service';
import { PipelinesService } from './modules/pipelines/pipelines.service';
// import { AuthService } from './modules/auth/auth.service';
import { HealthService } from './modules/health/health.service';
// import { InputsClientService } from './clients/inputs/client.service';
// import { TransformationsClientService } from './clients/transformations/client.service';
// import { OutputsClientService } from './clients/outputs/client.service';
// import { PipelinesClientService } from './clients/pipelines/client.service';
import { InputsClientService } from './clients/inputs/client.service';
import { TransformationsClientService } from './clients/transformations/client.service';
import { OutputsClientService } from './clients/outputs/client.service';
import { PipelinesClientService } from './clients/pipelines/client.service';
import { AuthClientService } from './clients/auth/client.service';
// import { InputsClientConfiguration } from './clients/inputs/client.config';
// import { OutputsClientConfiguration } from './clients/outputs/client.config';
// import { TransformationsClientConfiguration } from './clients/transformations/client.config';
import { OutputsClientConfiguration } from './clients/outputs/client.config';
import { TransformationsClientConfiguration } from './clients/transformations/client.config';
import { AuthClient } from './clients/auth/client.config';
import { InputsClientConfiguration } from './clients/inputs/client.config';
import { PipelinesClientConfiguration } from './clients/pipelines/client.config';
const authClient = new AuthClient();
const inputClient = new InputsClientConfiguration();
const outputClient = new OutputsClientConfiguration();
const pipelineClient = new PipelinesClientConfiguration();
const transformationClient = new TransformationsClientConfiguration();
@Module({
controllers: [
// InputsController,
// TransformationsController,
// OutputsController,
// PipelinesController,
InputsController,
TransformationsController,
OutputsController,
PipelinesController,
AuthController,
HealthController,
],
@@ -44,13 +49,13 @@ const authClient = new AuthClient();
InputsService,
TransformationsService,
OutputsService,
// PipelinesService,
PipelinesService,
// AuthService,
HealthService,
// InputsClientService,
// TransformationsClientService,
// OutputsClientService,
// PipelinesClientService,
InputsClientService,
TransformationsClientService,
OutputsClientService,
PipelinesClientService,
AuthClientService,
],
imports: [
@@ -59,23 +64,27 @@ const authClient = new AuthClient();
}),
ClientsModule.register([
// {
// name: 'INPUTS_PACKAGE',
// ...InputsClientConfiguration,
// },
{
name: 'INPUTS_PACKAGE',
...inputClient.config(),
},
// {
// name: 'TRANSFORMATIONS_PACKAGE',
// ...TransformationsClientConfiguration,
// },
// {
// name: 'OUTPUTS_PACKAGE',
// ...OutputsClientConfiguration,
// },
{
name: 'TRANSFORMATIONS_PACKAGE',
...transformationClient.config(),
},
{
name: 'OUTPUTS_PACKAGE',
...outputClient.config(),
},
{
name: 'AUTH_PACKAGE',
...authClient.config(),
},
{
name: 'PIPELINES_PACKAGE',
...pipelineClient.config(),
},
]),
],
})
+22 -16
View File
@@ -1,17 +1,23 @@
// import { join } from 'path';
// import { ClientOptions, Transport } from '@nestjs/microservices';
import { credentials } from '@grpc/grpc-js';
import { ClientOptions, Transport } from '@nestjs/microservices';
// export const InputsClientConfiguration: ClientOptions = {
// transport: Transport.GRPC,
// options: {
// //url: `${process.env.USERS_SVC_URL}:${process.env.USERS_SVC_PORT}`,
// url: `127.0.0.1:50052`,
// package: 'input',
// protoPath: join(__dirname, '..', 'proto', 'input.proto'),
// loader: {
// enums: String,
// objects: true,
// arrays: true,
// },
// },
// };
import { InputProtofile } from '@victorradael/protospack';
export class InputsClientConfiguration {
config(): ClientOptions {
return {
transport: Transport.GRPC,
options: {
url: process.env.INFACTORY_URL,
package: 'input',
// credentials: credentials.createSsl(),
protoPath: InputProtofile,
loader: {
enums: String,
objects: true,
arrays: true,
},
},
};
}
}
+176 -55
View File
@@ -1,64 +1,185 @@
// import {
// Get,
// Post,
// Controller,
// Delete,
// OnModuleInit,
// Put,
// Param,
// } from '@nestjs/common';
// import { Client, ClientGrpc, Payload } from '@nestjs/microservices';
// import { CreateInputGrpcClientDto } from './dto/create-input-grpc-client.dto';
// import { UpdateInputGrpcClientDto } from './dto/update-input-grpc-client.dto';
// import { InputGrpcClientService } from './input-grpc-client.service';
// import { GrpcClientConfiguration } from './client.config';
// import { TestConnectionDTO } from './dto/test-connection-grpc-client.dto';
// import { ApiTags } from '@nestjs/swagger';
import {
OnModuleInit,
Inject,
} from '@nestjs/common';
import { ClientGrpc } from '@nestjs/microservices';
import { InputService } from '@victorradael/protospack';
import { ICreateInputRequest, IIdRequest, ITestConnectionRequest, UpdateInputRequest } from './interfaces';
// @Controller('grpc/input')
// export class InputsClientService implements OnModuleInit {
// @Client(GrpcClientConfiguration)
// private inputServiceClient: ClientGrpc;
export class InputsClientService implements OnModuleInit {
private inputService: InputService;
constructor(
@Inject('INPUTS_PACKAGE') private readonly grpcClient: ClientGrpc,
) {}
// private inputService: InputGrpcClientService;
onModuleInit() {
this.inputService =
this.grpcClient.getService<InputService>(
'InputService',
);
}
// onModuleInit() {
// this.inputService =
// this.inputServiceClient.getService<InputGrpcClientService>(
// 'InputService',
// );
// }
async create(createInputDto: ICreateInputRequest ) {
console.log('InputClientService', 'Create');
// @Post()
// async create(@Payload() createInputDto: CreateInputGrpcClientDto) {
// return this.inputService.create(createInputDto);
// }
const createInputResponse = await new Promise((resolve, reject) => {
this.inputService.Create(createInputDto).subscribe({
next(x) {
resolve(x);
},
error(err) {
console.log('Observable Error');
reject(err);
},
complete() {
console.log('done');
},
});
})
.then((res) => res)
.catch((err) => {
throw new Error(err);
});
// @Get()
// list() {
// return this.inputService.list();
// }
return createInputResponse;
}
// @Get(':id')
// show(@Param() id: string) {
// return this.inputService.show(id);
// }
// @Put(':id')
// update(
// @Payload() updateInputDto: UpdateInputGrpcClientDto,
// @Param() id: string,
// ) {
// return this.inputService.update(id, updateInputDto);
// }
async findOne(data: IIdRequest ) {
console.log('InputClientService', 'FindOne');
// @Delete(':id')
// remove(@Param() id: string) {
// return this.inputService.remove(id);
// }
const { id } = data
// @Get('/test-connection')
// testConnection(@Payload() testConnectionDTO: TestConnectionDTO) {
// return this.inputService.testConnection(testConnectionDTO);
// }
// }
const findOneInputResponse = await new Promise((resolve, reject) => {
this.inputService.FindOne({id}).subscribe({
next(x) {
resolve(x);
},
error(err) {
console.log('Observable Error');
reject(err);
},
complete() {
console.log('done');
},
});
})
.then((res) => res)
.catch((err) => {
throw new Error(err);
});
return findOneInputResponse;
}
async findAll(data) {
console.log('InputClientService', 'FindAll');
const findAllInputResponse = await new Promise((resolve, reject) => {
this.inputService.FindAll({}).subscribe({
next(x) {
resolve(x);
},
error(err) {
console.log('Observable Error');
reject(err);
},
complete() {
console.log('done');
},
});
})
.then((res) => res)
.catch((err) => {
throw new Error(err);
});
return findAllInputResponse;
}
async update(updateInputDTO:UpdateInputRequest) {
console.log('InputClientService', 'Update');
console.log(updateInputDTO)
const updateInputResponse = await new Promise((resolve, reject) => {
this.inputService.Update(updateInputDTO).subscribe({
next(x) {
console.log(x)
resolve(x);
},
error(err) {
console.log('Observable Error');
reject(err);
},
complete() {
console.log('done');
},
});
})
.then((res) => res)
.catch((err) => {
throw new Error(err);
});
return updateInputResponse;
}
async remove(idRequest:IIdRequest) {
console.log('InputClientService', 'Remove');
const removeInputResponse = await new Promise((resolve, reject) => {
this.inputService.Remove(idRequest).subscribe({
next(x) {
resolve(x);
},
error(err) {
console.log('Observable Error');
reject(err);
},
complete() {
console.log('done');
},
});
})
.then((res) => res)
.catch((err) => {
throw new Error(err);
});
return removeInputResponse;
}
async testConnection(data:ITestConnectionRequest) {
console.log('InputClientService', 'TestCOnnection');
const testConnectionResponse = await new Promise((resolve, reject) => {
this.inputService.TestConnection(data).subscribe({
next(x) {
resolve(x);
},
error(err) {
console.log('Observable Error');
reject(err);
},
complete() {
console.log('done');
},
});
})
.then((res) => res)
.catch((err) => {
throw new Error(err);
});
return testConnectionResponse;
}
}
+56
View File
@@ -0,0 +1,56 @@
interface Values {
jdbc_user: string;
jdbc_password: string;
database: string;
endpoint: string;
tables: string[];
port: string;
engine: string;
schema: string;
}
interface Cron {
hours: string[];
hour_interval: boolean;
hour_resourse: boolean;
hour_resourse_value: number;
month_day: string[];
month_day_interval: boolean;
month_day_resourse: boolean;
month_day_resourse_value: number;
month: string[];
month_interval: boolean;
month_resourse: boolean;
month_resourse_value: number;
week_days: string[];
week_days_interval: boolean;
week_days_resourse: boolean;
week_days_resourse_value: number;
}
export interface ICreateInputRequest {
cron: Cron;
name: string;
plugin: string;
values: Values;
operation: string;
}
export interface IIdRequest{
id:string;
}
interface UpdateInputRequest {
id: string;
cron: Cron;
name: string;
plugin: string;
values: Values;
operation: string;
}
export interface ITestConnectionRequest {
plugin: string;
values: Values;
}
+21 -16
View File
@@ -1,17 +1,22 @@
// import { join } from 'path';
// import { ClientOptions, Transport } from '@nestjs/microservices';
import { OutputProtofile } from '@victorradael/protospack';
import { ClientOptions, Transport } from '@nestjs/microservices';
import { credentials } from '@grpc/grpc-js';
// export const OutputsClientConfiguration: ClientOptions = {
// transport: Transport.GRPC,
// options: {
// //url: `${process.env.USERS_SVC_URL}:${process.env.USERS_SVC_PORT}`,
// url: `127.0.0.1:50053`,
// package: 'output',
// protoPath: join(__dirname, '..', 'proto', 'output.proto'),
// loader: {
// enums: String,
// objects: true,
// arrays: true,
// },
// },
// };
export class OutputsClientConfiguration {
config(): ClientOptions {
return {
transport: Transport.GRPC,
options: {
url: process.env.OUTFACTORY_URL,
package: 'output',
// credentials: credentials.createSsl(),
protoPath: OutputProtofile,
loader: {
enums: String,
objects: true,
arrays: true,
},
},
};
}
};
+158 -50
View File
@@ -1,57 +1,165 @@
// import {
// Controller,
// Delete,
// Get,
// OnModuleInit,
// Param,
// Post,
// Put,
// } from '@nestjs/common';
// import {
// Client,
// ClientGrpc,
// MessagePattern,
// Payload,
// } from '@nestjs/microservices';
// import { OutputsService } from './outputs.service';
// import { CreateOutputDto } from './dto/create-output.dto';
// import { UpdateOutputDto } from './dto/update-output.dto';
// import { ApiTags } from '@nestjs/swagger';
// import { GrpcClientConfiguration } from './client.config';
import {
Controller,
Delete,
Get,
Inject,
OnModuleInit,
Param,
Post,
Put,
} from '@nestjs/common';
import {
ClientGrpc,
Payload,
} from '@nestjs/microservices';
import { ApiTags } from '@nestjs/swagger';
import { OutputsServiceInterface } from '@victorradael/protospack';
import { objectCamelToSnake } from 'src/utils/CaseConverter';
import { ICreateOutputRequest, IIdRequest, IOutputUpdateRequest } from './interfaces';
// @Controller('output')
// export class OutputsClientService implements OnModuleInit {
// @Client(GrpcClientConfiguration)
// private outputServiceClient: ClientGrpc;
@Controller('output')
export class OutputsClientService implements OnModuleInit {
private outputService: OutputsServiceInterface;
constructor(
@Inject('OUTPUTS_PACKAGE')private readonly grpcClient: ClientGrpc,
){}
// private outputService: OutputsService;
onModuleInit() {
this.outputService =
this.grpcClient.getService<OutputsServiceInterface>('OutputService');
}
// onModuleInit() {
// this.outputService =
// this.outputServiceClient.getService<OutputsService>('OutputService');
// }
// @Post()
// create(@Payload() createOutputDto: CreateOutputDto) {
// return this.outputService.create(createOutputDto);
// }
async create(@Payload() createOutputDto:ICreateOutputRequest ) {
console.log('OutputClientService', 'Create');
// @Get()
// list() {
// return this.outputService.list();
// }
const createOutputResponse = await new Promise((resolve, reject) => {
this.outputService.create(createOutputDto).subscribe({
next(x) {
resolve(x);
},
error(err) {
console.log('Observable Error');
reject(err);
},
complete() {
console.log('done');
},
});
})
.then((res) => res)
.catch((err) => {
throw new Error(err);
});
const convertedItem = objectCamelToSnake(createOutputResponse["item"])
createOutputResponse["item"] = convertedItem
// @Get(':id')
// show(@Param() id: string) {
// return this.outputService.show(id);
// }
return createOutputResponse;
}
// @Put(':id')
// update(@Param() id: string, @Payload() updateOutputDto: UpdateOutputDto) {
// return this.outputService.update(id, updateOutputDto);
// }
async findAll() {
console.log('OutputClientService', 'FindAll');
// @Delete(':id')
// remove(@Param() id: string) {
// return this.outputService.remove(id);
// }
// }
const findAllOutputResponse = await new Promise((resolve, reject) => {
this.outputService.findAll({}).subscribe({
next(x) {
resolve(x);
},
error(err) {
console.log('Observable Error');
reject(err);
},
complete() {
console.log('done');
},
});
})
.then((res) => res)
.catch((err) => {
throw new Error(err);
});
const convertedOutputs = findAllOutputResponse['outputs'].map((ot)=>{
return objectCamelToSnake(ot)
})
return {outputs:convertedOutputs};
}
async findOne({id}: IIdRequest) {
console.log('OutputClientService', 'FindOne');
const findOneOutputResponse = await new Promise((resolve, reject) => {
this.outputService.findOne({id}).subscribe({
next(x) {
resolve(x);
},
error(err) {
console.log('Observable Error');
reject(err);
},
complete() {
console.log('done');
},
});
})
.then((res) => res)
.catch((err) => {
throw new Error(err);
});
return objectCamelToSnake(findOneOutputResponse);
}
async update(updateOutPutDTO: IOutputUpdateRequest) {
console.log('OutputClientService', 'Update');
const updateOutputResponse = await new Promise((resolve, reject) => {
this.outputService.update(updateOutPutDTO).subscribe({
next(x) {
resolve(x);
},
error(err) {
console.log('Observable Error');
reject(err);
},
complete() {
console.log('done');
},
});
})
.then((res) => res)
.catch((err) => {
throw new Error(err);
});
return objectCamelToSnake(updateOutputResponse);
}
async remove({id}:IIdRequest) {
console.log('OutputClientService', 'Remove');
const removeOutputResponse = await new Promise((resolve, reject) => {
this.outputService.remove({id}).subscribe({
next(x) {
resolve(x);
},
error(err) {
console.log('Observable Error');
reject(err);
},
complete() {
console.log('done');
},
});
})
.then((res) => res)
.catch((err) => {
throw new Error(err);
});
return removeOutputResponse;
}
}
+22
View File
@@ -0,0 +1,22 @@
export interface ICreateOutputRequest {
operation: string;
name: string;
plugin: string;
values: Values;
}
export interface Values {
prefix: string;
}
export interface IIdRequest{
id:string;
}
export interface IOutputUpdateRequest {
id: string;
operation: string;
values: Values;
plugin: string;
name: string;
}
+21 -16
View File
@@ -1,17 +1,22 @@
// import { join } from 'path';
// import { ClientOptions, Transport } from '@nestjs/microservices';
import { ClientOptions, Transport } from '@nestjs/microservices';
import { PipelineProtofile } from '@victorradael/protospack';
import { credentials } from '@grpc/grpc-js';
// export const PipelinesClientConfiguration: ClientOptions = {
// transport: Transport.GRPC,
// options: {
// //url: `${process.env.USERS_SVC_URL}:${process.env.USERS_SVC_PORT}`,
// url: `127.0.0.1:50054`,
// package: 'pipeline',
// protoPath: join(__dirname, '..', 'proto', 'pipeline.proto'),
// loader: {
// enums: String,
// objects: true,
// arrays: true,
// },
// },
// };
export class PipelinesClientConfiguration {
config(): ClientOptions {
return {
transport: Transport.GRPC,
options: {
url: process.env.PIFACTORY_URL,
package: 'pipeline',
// credentials: credentials.createSsl(),
protoPath: PipelineProtofile,
loader: {
enums: String,
objects: true,
arrays: true,
},
},
};
}
};
+201 -58
View File
@@ -1,68 +1,211 @@
// import {
// Controller,
// Delete,
// Get,
// OnModuleInit,
// Param,
// Post,
// Put,
// } from '@nestjs/common';
// import {
// Client,
// ClientGrpc,
// MessagePattern,
// Payload,
// } from '@nestjs/microservices';
// import { PipelinesService } from './pipelines.service';
// import { CreatePipelineDto } from './dto/create-pipeline.dto';
// import { UpdatePipelineDto } from './dto/update-pipeline.dto';
// import { GrpcClientConfiguration } from './client.config';
import {
Controller,
Delete,
Get,
Inject,
OnModuleInit,
Param,
Post,
Put,
} from '@nestjs/common';
import {
Client,
ClientGrpc,
MessagePattern,
Payload,
} from '@nestjs/microservices';
import { PipelinesServiceInterface } from '@victorradael/protospack';
import { ICreatePipelineDto, IdRequest, IGetPipelineLogsRequest, IUpdatePipelineRequest } from './interfaces';
// @Controller('pipeline')
// export class PipelinesClientService implements OnModuleInit {
// @Client(GrpcClientConfiguration)
// private pipelineServiceClient: ClientGrpc;
export class PipelinesClientService implements OnModuleInit {
private pipelineService: PipelinesServiceInterface;
constructor(
@Inject('PIPELINES_PACKAGE') private readonly grpcClient: ClientGrpc,
){}
// private pipelineService: PipelinesService;
onModuleInit() {
this.pipelineService =
this.grpcClient.getService<PipelinesServiceInterface>(
'PipelineService',
);
}
// onModuleInit() {
// this.pipelineService =
// this.pipelineServiceClient.getService<PipelinesService>(
// 'PipelineService',
// );
// }
// @Post()
// create(@Payload() createPipelineDto: CreatePipelineDto) {
// return this.pipelineService.create(createPipelineDto);
// }
async create(@Payload() createPipelineDto: ICreatePipelineDto ) {
// @Get()
// list() {
// return this.pipelineService.list();
// }
console.log('PipelinesClientService', 'Create');
// @Get(':id')
// show(@Param() id: string) {
// return this.pipelineService.show(id);
// }
const createPipelineResponse = await new Promise((resolve, reject) => {
this.pipelineService.create(createPipelineDto).subscribe({
next(x) {
resolve(x);
},
error(err) {
console.log('Observable Error');
reject(err);
},
complete() {
console.log('done');
},
});
})
.then((res) => res)
.catch((err) => {
throw new Error(err);
});
// @Put(':id')
// update(@Param() id: string, @Payload() updatePipelineDto: UpdatePipelineDto) {
// return this.pipelineService.update(id, updatePipelineDto);
// }
return createPipelineResponse;
}
// @Delete()
// remove(@Param() id: string) {
// return this.pipelineService.remove(id);
// }
async findAll() {
console.log('PipelinesClientService', 'FindAll');
// @Post()
// getPipelineLogsMessages(@Param() id: string, @Payload() details: string) {
// return this.pipelineService.getPipelineLogsMessages(id, details);
// }
const findAllPipelineResponse = await new Promise((resolve, reject) => {
this.pipelineService.findAll({}).subscribe({
next(x) {
resolve(x);
},
error(err) {
console.log('Observable Error');
reject(err);
},
complete() {
console.log('done');
},
});
})
.then((res) => res)
.catch((err) => {
throw new Error(err);
});
// getPipelineStatus(id: string) {
// return this.pipelineService.getPipelineStatus(id);
// }
// }
return findAllPipelineResponse;
}
async findOne({id}: IdRequest) {
console.log('PipelinesClientService', 'FindOne');
const findOnePipelineResponse = await new Promise((resolve, reject) => {
this.pipelineService.findOne({id}).subscribe({
next(x) {
resolve(x);
},
error(err) {
console.log('Observable Error');
reject(err);
},
complete() {
console.log('done');
},
});
})
.then((res) => res)
.catch((err) => {
throw new Error(err);
});
return findOnePipelineResponse;
}
async update(UpdatePipelineRequest:IUpdatePipelineRequest) {
console.log('PipelinesClientService', 'Update');
const updatePipelineResponse = await new Promise((resolve, reject) => {
this.pipelineService.update(UpdatePipelineRequest).subscribe({
next(x) {
resolve(x);
},
error(err) {
console.log('Observable Error');
reject(err);
},
complete() {
console.log('done');
},
});
})
.then((res) => res)
.catch((err) => {
throw new Error(err);
});
return updatePipelineResponse;
}
async remove({id}:IdRequest) {
console.log('PipelinesClientService', 'Remove');
const removePipelineResponse = await new Promise((resolve, reject) => {
this.pipelineService.remove({id}).subscribe({
next(x) {
resolve(x);
},
error(err) {
console.log('Observable Error');
reject(err);
},
complete() {
console.log('done');
},
});
})
.then((res) => res)
.catch((err) => {
throw new Error(err);
});
return removePipelineResponse;
}
async getPipelineLogsMessages( data:IGetPipelineLogsRequest) {
console.log('PipelinesClientService', 'GetPipelineLogsMessages');
const logsPipelineResponse = await new Promise((resolve, reject) => {
this.pipelineService.getPipelineLogs(data).subscribe({
next(x) {
resolve(x);
},
error(err) {
console.log('Observable Error');
reject(err);
},
complete() {
console.log('done');
},
});
})
.then((res) => res)
.catch((err) => {
throw new Error(err);
});
return logsPipelineResponse;
}
async getPipelineStatus({id}:IdRequest) {
console.log('PipelinesClientService', 'GetPipelineStatus');
const statusPipelineResponse = await new Promise((resolve, reject) => {
this.pipelineService.getPipelineStatus({id}).subscribe({
next(x) {
resolve(x);
},
error(err) {
console.log('Observable Error');
reject(err);
},
complete() {
console.log('done');
},
});
})
.then((res) => res)
.catch((err) => {
throw new Error(err);
});
return statusPipelineResponse;
}
}
+28
View File
@@ -0,0 +1,28 @@
export interface ICreatePipelineDto {
input: IdRequest;
transformations: IdRequest[];
output: IdRequest;
tags: string[];
name: string;
description: string;
}
export interface IdRequest {
id: string;
}
export interface IUpdatePipelineRequest {
input: IdRequest;
transformations: IdRequest[];
output: IdRequest;
tags: string[];
name: string;
description: string;
id: string;
}
export interface IGetPipelineLogsRequest {
id: string;
details: string;
}
+21 -16
View File
@@ -1,17 +1,22 @@
// import { join } from 'path';
// import { ClientOptions, Transport } from '@nestjs/microservices';
import { ClientOptions, Transport } from '@nestjs/microservices';
import { TransformationProtofile } from '@victorradael/protospack';
import { credentials } from '@grpc/grpc-js';
// export const TransformationsClientConfiguration: ClientOptions = {
// transport: Transport.GRPC,
// options: {
// //url: `${process.env.USERS_SVC_URL}:${process.env.USERS_SVC_PORT}`,
// url: `127.0.0.1:50054`,
// package: 'transformation',
// protoPath: join(__dirname, '..', 'proto', 'transformation.proto'),
// loader: {
// enums: String,
// objects: true,
// arrays: true,
// },
// },
// };
export class TransformationsClientConfiguration {
config(): ClientOptions {
return {
transport: Transport.GRPC,
options: {
url: process.env.TRFACTORY_URL,
package: 'transformation',
// credentials: credentials.createSsl(),
protoPath: TransformationProtofile,
loader: {
enums: String,
objects: true,
arrays: true,
},
},
};
}
};
+151 -57
View File
@@ -1,65 +1,159 @@
// import {
// Controller,
// Delete,
// Get,
// OnModuleInit,
// Param,
// Post,
// Put,
// } from '@nestjs/common';
// import {
// Client,
// ClientGrpc,
// MessagePattern,
// Payload,
// } from '@nestjs/microservices';
// import { TransformationsService } from './transformations.service';
// import { CreateTransformationDto } from './dto/create-transformation.dto';
// import { UpdateTransformationDto } from './dto/update-transformation.dto';
// import { ApiTags } from '@nestjs/swagger';
// import { GrpcClientConfiguration } from './client.config';
import {
Controller,
Delete,
Get,
Inject,
OnModuleInit,
Param,
Post,
Put,
} from '@nestjs/common';
import {
Client,
ClientGrpc,
MessagePattern,
Payload,
} from '@nestjs/microservices';
import { ApiTags } from '@nestjs/swagger';
import { TransformationsServiceInterface } from '@victorradael/protospack';
import { ICreateTransformationElement, ICreateTransformationsRequest, IdRequest, IUpdateTransformationRequest } from './interfaces';
// @Controller('transformation')
// export class TransformationsClientService implements OnModuleInit {
// @Client(GrpcClientConfiguration)
// private transformationServiceClient: ClientGrpc;
@Controller('transformation')
export class TransformationsClientService implements OnModuleInit {
private transformationService: TransformationsServiceInterface;
constructor(
@Inject('TRANSFORMATIONS_PACKAGE') private readonly grpcClient: ClientGrpc,
) {}
// private transformationService: TransformationsService;
onModuleInit() {
this.transformationService =
this.grpcClient.getService<TransformationsServiceInterface>(
'TransformationService',
);
}
// onModuleInit() {
// this.transformationService =
// this.transformationServiceClient.getService<TransformationsService>(
// 'TransformationService',
// );
// }
@Post()
async create(createTransformationsDto: ICreateTransformationsRequest) {
console.log('TransformationClientService', 'Create');
// @Post()
// create(@Payload() createTransformationDto: CreateTransformationDto[]) {
// return createTransformationDto.map((transf) =>
// this.transformationService.create(transf),
// );
// }
const createTransformationResponse = await new Promise((resolve, reject) => {
this.transformationService.create(createTransformationsDto).subscribe({
next(x) {
resolve(x);
},
error(err) {
console.log('Observable Error');
reject(err);
},
complete() {
console.log('done');
},
});
})
.then((res) => res)
.catch((err) => {
throw new Error(err);
});
return createTransformationResponse;
}
// @Get()
// list() {
// return this.transformationService.list();
// }
async findAll() {
console.log('TransformationClientService', 'FindAll');
// @Get(':id')
// show(@Payload() id: string) {
// return this.transformationService.show(id);
// }
const findAllTransformationResponse = await new Promise((resolve, reject) => {
this.transformationService.findAll({}).subscribe({
next(x) {
resolve(x);
},
error(err) {
console.log('Observable Error');
reject(err);
},
complete() {
console.log('done');
},
});
})
.then((res) => res)
.catch((err) => {
throw new Error(err);
});
// @Put(':id')
// update(
// @Param() id: string,
// @Payload() updateTransformationDto: UpdateTransformationDto,
// ) {
// return this.transformationService.update(id, updateTransformationDto);
// }
return findAllTransformationResponse;
}
// @Delete(':id')
// remove(@Param() id: string) {
// return this.transformationService.remove(id);
// }
// }
async findOne({id}: IdRequest) {
console.log('TransformationClientService', 'FindOne');
const findOneTransformationResponse = await new Promise((resolve, reject) => {
this.transformationService.findOne({id}).subscribe({
next(x) {
resolve(x);
},
error(err) {
console.log('Observable Error');
reject(err);
},
complete() {
console.log('done');
},
});
})
.then((res) => res)
.catch((err) => {
throw new Error(err);
});
return findOneTransformationResponse;
}
async update(updateTransformationDTO: IUpdateTransformationRequest) {
console.log('TransformationClientService', 'Update');
const updateTransformationResponse = await new Promise((resolve, reject) => {
this.transformationService.update(updateTransformationDTO).subscribe({
next(x) {
resolve(x);
},
error(err) {
console.log('Observable Error');
reject(err);
},
complete() {
console.log('done');
},
});
})
.then((res) => res)
.catch((err) => {
throw new Error(err);
});
return updateTransformationResponse;
}
async remove({id}: IdRequest) {
console.log('TransformationClientService', 'Remove');
const removeTransformationResponse = await new Promise((resolve, reject) => {
this.transformationService.remove({id}).subscribe({
next(x) {
resolve(x);
},
error(err) {
console.log('Observable Error');
reject(err);
},
complete() {
console.log('done');
},
});
})
.then((res) => res)
.catch((err) => {
throw new Error(err);
});
return removeTransformationResponse;
}
}
+31
View File
@@ -0,0 +1,31 @@
export interface ICreateTransformationsRequest {
transformations: ICreateTransformationElement[];
}
interface Param {
base_column?: string;
column_name?: string;
n_digits?: number;
start_index?: number;
randbelow?: number;
const?: string;
}
export interface ICreateTransformationElement {
type: string;
params: Param[];
input_source: string;
table: string;
}
export interface IdRequest{
id:string;
}
export interface IUpdateTransformationRequest {
created_at?: string;
id?: string;
client_id?: string;
params: Param[];
type?: string;
input_source?: string;
table?: string;
}
+90 -75
View File
@@ -1,83 +1,98 @@
// import {
// Body,
// Controller,
// Delete,
// Get,
// Param,
// Post,
// Put,
// Redirect,
// } from '@nestjs/common';
// import { Payload } from '@nestjs/microservices';
// import axios from 'axios';
// import { Console } from 'console';
// // import { CreateInputGrpcClientDto } from './dto/create-input-grpc-client.dto';
// // import { UpdateInputGrpcClientDto } from './dto/update-input-grpc-client.dto';
import {
Body,
Controller,
Delete,
Get,
Param,
Post,
Put,
} from '@nestjs/common';
import axios from 'axios';
import { InputsService } from './inputs.service';
import { InputsClientService } from 'src/clients/inputs/client.service';
import { Payload } from '@nestjs/microservices';
// @Controller('input')
// export class InputsController {
// @Get('/test-connection')
// async testConnection() {
// console.log(
// process.env.DEV_URL + `/test-connection`,
// 'ON TEST CONNECTION ROUTE',
// );
// await axios
// .get(process.env.DEV_URL + `/test-connection`)
// .then((response) => {
// return response;
// });
// }
@Controller('input')
export class InputsController {
// @Post()
// async create(@Body() createInputDto: CreateInputGrpcClientDto) {
// console.log(createInputDto);
// console.log(process.env.DEV_URL + `/input`, 'ON CREATE ROUTE');
constructor( private inputsClientService:InputsClientService){}
// await axios
// .post(process.env.DEV_URL + '/input', createInputDto)
// .then((response) => {
// return response;
// });
// }
@Get('/test-connection')
async testConnection(@Body() data) {
console.log(
process.env.DEV_URL + `/test-connection`,
'ON TEST CONNECTION ROUTE',
);
console.log(data)
// @Get()
// async list() {
// console.log(process.env.DEV_URL + `/input`, 'ON GET ROUTE');
// await axios.get(process.env.DEV_URL + `/input`).then((response) => {
// return response;
// });
// }
const inputService = new InputsService(this.inputsClientService)
const response = await inputService.testConnection(data)
// @Get('/:id')
// async show(@Param() id: string) {
// console.log(process.env.DEV_URL + `/input/${id}`, 'ON SHOW ROUTE');
// await axios.get(process.env.DEV_URL + `/input/${id}`).then((response) => {
// return response;
// });
// }
return response;
}
// @Put(':id')
// async update(
// @Payload() updateInputDto: UpdateInputGrpcClientDto,
// @Param() id: string,
// ) {
// console.log(process.env.DEV_URL + `/input/${id}`, 'ON UPDATE ROUTE');
// await axios
// .put(process.env.DEV_URL + `input/${id}`, updateInputDto)
// .then((response) => {
// return response;
// });
// }
@Post()
async create(@Body() createInputDto) {
console.log(process.env.DEV_URL + `/input`, 'ON CREATE ROUTE');
// @Delete(':id')
// async delete(@Param() id: string) {
// console.log(process.env.DEV_URL + `/input/${id}`, 'ON DELETE ROUTE');
const inputService = new InputsService(this.inputsClientService)
const response = await inputService.create(createInputDto)
// await axios
// .delete(process.env.DEV_URL + `/input/${id}`)
// .then((response) => {
// return response;
// });
// }
// }
return response;
}
@Get()
async findAll() {
console.log(process.env.DEV_URL + `/input`, 'ON FIND ALL ROUTE');
const inputService = new InputsService(this.inputsClientService)
const response = await inputService.findAll()
return response;
}
@Get('/:id')
async findOne(@Param() params) {
const { id } = params
console.log(process.env.DEV_URL + `/input/${id}`, 'ON FIND ONE ROUTE');
const inputService = new InputsService(this.inputsClientService)
const response = await inputService.findOne(id)
return response;
}
@Put(':id')
async update(
@Payload() updateInputDto,
@Param() params,
) {
const {id} = params;
console.log(process.env.DEV_URL + `/input/${id}`, 'ON UPDATE ROUTE');
const inputService = new InputsService(this.inputsClientService)
const response = await inputService.update(id,updateInputDto)
return response;
}
@Delete(':id')
async delete(@Param() params) {
const {id} = params
console.log(process.env.DEV_URL + `/input/${id}`, 'ON DELETE ROUTE');
const inputService = new InputsService(this.inputsClientService)
const response = await inputService.remove(id)
return response;
}
}
+82 -3
View File
@@ -1,8 +1,87 @@
import { Injectable } from '@nestjs/common';
import { HttpException, HttpStatus, Injectable } from '@nestjs/common';
import { InputsClientService } from 'src/clients/inputs/client.service';
@Injectable()
export class InputsService {
check() {
return { message: 'Ok' };
constructor( private inputClient: InputsClientService){}
async create(data){
try{
const createInputResponse = await this.inputClient.create(data)
return createInputResponse;
}catch(err){
throw new HttpException(err.message,HttpStatus.NOT_FOUND)
}
}
async findAll(){
try{
const findAllInputResponse = await this.inputClient.findAll({})
return findAllInputResponse;
}catch(err){
throw new HttpException(err.message,HttpStatus.NOT_FOUND)
}
}
async findOne(id:string){
try{
const findOneInputResponse = await this.inputClient.findOne({id})
return findOneInputResponse;
}catch(err){
throw new HttpException(err.message,HttpStatus.NOT_FOUND)
}
}
async update(id:string,data){
try{
const updateInputResponse = await this.inputClient.update({id,...data})
return updateInputResponse;
}catch(err){
throw new HttpException(err.message,HttpStatus.NOT_FOUND)
}
}
async remove(id:string){
try{
const removeInputResponse = await this.inputClient.remove({id})
return removeInputResponse;
}catch(err){
throw new HttpException(err.message,HttpStatus.NOT_FOUND)
}
}
async testConnection(data){
try{
const testConnectionInputResponse = await this.inputClient.testConnection(data)
return testConnectionInputResponse;
}catch(err){
throw new HttpException(err.message,HttpStatus.NOT_FOUND)
}
}
}
+69 -75
View File
@@ -1,83 +1,77 @@
// import {
// Body,
// Controller,
// Delete,
// Get,
// Param,
// Post,
// Put,
// Redirect,
// } from '@nestjs/common';
// import { Payload } from '@nestjs/microservices';
// import axios from 'axios';
// import { Console } from 'console';
// // import { CreateInputGrpcClientDto } from './dto/create-input-grpc-client.dto';
// // import { UpdateInputGrpcClientDto } from './dto/update-input-grpc-client.dto';
import {
Body,
Controller,
Delete,
Get,
Param,
Post,
Put,
Redirect,
} from '@nestjs/common';
import { Payload } from '@nestjs/microservices';
import { OutputsClientService } from 'src/clients/outputs/client.service';
import { OutputsService } from './outputs.service';
// @Controller('outputs')
// export class OutputsController {
// @Get('/test-connection')
// async testConnection() {
// console.log(
// process.env.DEV_URL + `/test-connection`,
// 'ON TEST CONNECTION ROUTE',
// );
// await axios
// .get(process.env.DEV_URL + `/test-connection`)
// .then((response) => {
// return response;
// });
// }
@Controller('outputs')
export class OutputsController {
// @Post()
// async create(@Body() createInputDto: CreateInputGrpcClientDto) {
// console.log(createInputDto);
// console.log(process.env.DEV_URL + `/input`, 'ON CREATE ROUTE');
constructor( private outputsClientService:OutputsClientService){}
// await axios
// .post(process.env.DEV_URL + '/input', createInputDto)
// .then((response) => {
// return response;
// });
// }
@Post()
async create(@Body() createOutputDto) {
console.log(process.env.DEV_URL + `/output`, 'ON CREATE ROUTE');
// @Get()
// async list() {
// console.log(process.env.DEV_URL + `/input`, 'ON GET ROUTE');
// await axios.get(process.env.DEV_URL + `/input`).then((response) => {
// return response;
// });
// }
const outputService = new OutputsService(this.outputsClientService)
const response = await outputService.create(createOutputDto)
// @Get('/:id')
// async show(@Param() id: string) {
// console.log(process.env.DEV_URL + `/input/${id}`, 'ON SHOW ROUTE');
// await axios.get(process.env.DEV_URL + `/input/${id}`).then((response) => {
// return response;
// });
// }
return response;
}
// @Put(':id')
// async update(
// @Payload() updateInputDto: UpdateInputGrpcClientDto,
// @Param() id: string,
// ) {
// console.log(process.env.DEV_URL + `/input/${id}`, 'ON UPDATE ROUTE');
// await axios
// .put(process.env.DEV_URL + `input/${id}`, updateInputDto)
// .then((response) => {
// return response;
// });
// }
@Get()
async findAll() {
console.log(process.env.DEV_URL + `/output`, 'ON Find All ROUTE');
// @Delete(':id')
// async delete(@Param() id: string) {
// console.log(process.env.DEV_URL + `/input/${id}`, 'ON DELETE ROUTE');
const outputService = new OutputsService(this.outputsClientService)
const response = await outputService.findAll()
// await axios
// .delete(process.env.DEV_URL + `/input/${id}`)
// .then((response) => {
// return response;
// });
// }
// }
return response;
}
@Get('/:id')
async findOne(@Param() params) {
const {id} = params;
console.log(process.env.DEV_URL + `/output/${id}`, 'ON Find One ROUTE');
const outputService = new OutputsService(this.outputsClientService)
const response = await outputService.findOne(id)
return response;
}
@Put(':id')
async update(
@Payload() updateOutputDto,
@Param() params,
) {
const {id} = params;
console.log(process.env.DEV_URL + `/output/${id}`, 'ON UPDATE ROUTE');
const outputService = new OutputsService(this.outputsClientService)
const response = await outputService.update(id,updateOutputDto)
return response;
}
@Delete(':id')
async delete(@Param() params) {
const {id} = params;
console.log(process.env.DEV_URL + `/output/${id}`, 'ON DELETE ROUTE');
const outputService = new OutputsService(this.outputsClientService)
const response = await outputService.remove(id)
return response;
}
}
+64 -3
View File
@@ -1,8 +1,69 @@
import { Injectable } from '@nestjs/common';
import { HttpException, HttpStatus, Injectable } from '@nestjs/common';
import { OutputsClientService } from 'src/clients/outputs/client.service';
@Injectable()
export class OutputsService {
check() {
return { message: 'Ok' };
constructor( private outputClient: OutputsClientService){}
async create(createOutputDto){
try{
const createOutputResponse = await this.outputClient.create(createOutputDto);
return createOutputResponse
}catch(err){
throw new HttpException(err.message,HttpStatus.NOT_FOUND)
}
}
async findOne(id:string){
try{
const findOneOutputResponse = await this.outputClient.findOne({id});
return findOneOutputResponse
}catch(err){
throw new HttpException(err.message,HttpStatus.NOT_FOUND)
}
}
async findAll(){
try{
const findAllOutputResponse = await this.outputClient.findAll();
return findAllOutputResponse
}catch(err){
throw new HttpException(err.message,HttpStatus.NOT_FOUND)
}
}
async update(id:string, data){
try{
const updateOutputResponse = await this.outputClient.update({id,...data});
return updateOutputResponse
}catch(err){
throw new HttpException(err.message,HttpStatus.NOT_FOUND)
}
}
async remove(id:string){
try{
const removeOutputResponse = await this.outputClient.remove({id});
return removeOutputResponse
}catch(err){
throw new HttpException(err.message,HttpStatus.NOT_FOUND)
}
}
}
+101 -75
View File
@@ -1,83 +1,109 @@
// import {
// Body,
// Controller,
// Delete,
// Get,
// Param,
// Post,
// Put,
// Redirect,
// } from '@nestjs/common';
// import { Payload } from '@nestjs/microservices';
// import axios from 'axios';
// import { Console } from 'console';
// // import { CreateInputGrpcClientDto } from './dto/create-input-grpc-client.dto';
// // import { UpdateInputGrpcClientDto } from './dto/update-input-grpc-client.dto';
import {
Body,
Controller,
Delete,
Get,
Param,
Post,
Put,
Redirect,
} from '@nestjs/common';
import { Payload } from '@nestjs/microservices';
import { PipelinesClientService } from 'src/clients/pipelines/client.service';
import { objectCamelToSnake } from 'src/utils/CaseConverter';
import { PipelinesService } from './pipelines.service';
// @Controller('pipelines')
// export class PipelinesController {
// @Get('/test-connection')
// async testConnection() {
// console.log(
// process.env.DEV_URL + `/test-connection`,
// 'ON TEST CONNECTION ROUTE',
// );
// await axios
// .get(process.env.DEV_URL + `/test-connection`)
// .then((response) => {
// return response;
// });
// }
@Controller('pipelines')
export class PipelinesController {
// @Post()
// async create(@Body() createInputDto: CreateInputGrpcClientDto) {
// console.log(createInputDto);
// console.log(process.env.DEV_URL + `/input`, 'ON CREATE ROUTE');
constructor( private pipelinesClientService:PipelinesClientService){}
// await axios
// .post(process.env.DEV_URL + '/input', createInputDto)
// .then((response) => {
// return response;
// });
// }
@Get(':id/status')
async getPipelineStatus(
@Param() params,
) {
const { id , details } = params;
console.log(process.env.DEV_URL + `/pipeline/${id}`, 'ON GET PIPELINE STATUS ROUTE');
// @Get()
// async list() {
// console.log(process.env.DEV_URL + `/input`, 'ON GET ROUTE');
// await axios.get(process.env.DEV_URL + `/input`).then((response) => {
// return response;
// });
// }
const pipelineService = new PipelinesService(this.pipelinesClientService)
const response = await pipelineService.getPipelineStatus(id)
// @Get('/:id')
// async show(@Param() id: string) {
// console.log(process.env.DEV_URL + `/input/${id}`, 'ON SHOW ROUTE');
// await axios.get(process.env.DEV_URL + `/input/${id}`).then((response) => {
// return response;
// });
// }
return response;
// @Put(':id')
// async update(
// @Payload() updateInputDto: UpdateInputGrpcClientDto,
// @Param() id: string,
// ) {
// console.log(process.env.DEV_URL + `/input/${id}`, 'ON UPDATE ROUTE');
// await axios
// .put(process.env.DEV_URL + `input/${id}`, updateInputDto)
// .then((response) => {
// return response;
// });
// }
}
// @Delete(':id')
// async delete(@Param() id: string) {
// console.log(process.env.DEV_URL + `/input/${id}`, 'ON DELETE ROUTE');
// await axios
// .delete(process.env.DEV_URL + `/input/${id}`)
// .then((response) => {
// return response;
// });
// }
// }
@Get(':id/:details')
async getPipelineLogs(
@Param() params,
) {
const { id , details } = params;
console.log(process.env.DEV_URL + `/pipeline/${id}`, 'ON GET PIPELINE LOGS ROUTE');
const pipelineService = new PipelinesService(this.pipelinesClientService)
const response = await pipelineService.getPipelineLogsMessages(id,details)
return response;
}
@Post()
async create(@Body() createPipelineDto) {
console.log(process.env.DEV_URL + `/pipelines`, 'ON CREATE ROUTE');
const pipelineService = new PipelinesService(this.pipelinesClientService)
const response = await pipelineService.create(createPipelineDto)
return response;
}
@Get()
async findAll() {
console.log(process.env.DEV_URL + `/pipeline`, 'ON Find All ROUTE');
const pipelineService = new PipelinesService(this.pipelinesClientService)
const response = await pipelineService.findAll()
return response;
}
@Get('/:id')
async findOne(@Param() params) {
const {id} = params;
console.log(process.env.DEV_URL + `/pipeline/${id}`, 'ON Find One ROUTE');
const pipelineService = new PipelinesService(this.pipelinesClientService)
const response = await pipelineService.findOne(id)
return response;
}
@Put(':id')
async update(
@Payload() updatePipelineDto,
@Param() params,
) {
const {id} = params;
console.log(process.env.DEV_URL + `/pipeline/${id}`, 'ON UPDATE ROUTE');
const pipelineService = new PipelinesService(this.pipelinesClientService)
const response = await pipelineService.update(id,updatePipelineDto)
return response;
}
@Delete(':id')
async delete(@Param() params) {
const {id} = params;
console.log(process.env.DEV_URL + `/pipeline/${id}`, 'ON DELETE ROUTE');
const pipelineService = new PipelinesService(this.pipelinesClientService)
const response = await pipelineService.remove(id)
return response;
}
}
+98 -7
View File
@@ -1,8 +1,99 @@
// import { Injectable } from '@nestjs/common';
import { HttpException, HttpStatus, Injectable } from '@nestjs/common';
import { PipelinesClientService } from 'src/clients/pipelines/client.service';
import { objectCamelToSnake } from 'src/utils/CaseConverter';
// @Injectable()
// export class PipelinesService {
// check() {
// return { message: 'Ok' };
// }
// }
@Injectable()
export class PipelinesService {
constructor( private pipelineClient: PipelinesClientService){}
async create(createPipelineDto){
try{
const createPipelineResponse = await this.pipelineClient.create(createPipelineDto);
return objectCamelToSnake(createPipelineResponse)
}catch(err){
console.log(err)
throw new HttpException(err.message,HttpStatus.NOT_FOUND)
}
}
async findOne(id:string){
try{
const findOnePipelineResponse = await this.pipelineClient.findOne({id});
return objectCamelToSnake(findOnePipelineResponse)
}catch(err){
throw new HttpException(err.message,HttpStatus.NOT_FOUND)
}
}
async findAll(){
try{
const findAllPipelineResponse = await this.pipelineClient.findAll();
return objectCamelToSnake(findAllPipelineResponse)
}catch(err){
throw new HttpException(err.message,HttpStatus.NOT_FOUND)
}
}
async update(id:string, data){
try{
const updatePipelineResponse = await this.pipelineClient.update({id,...data});
return objectCamelToSnake(updatePipelineResponse)
}catch(err){
throw new HttpException(err.message,HttpStatus.NOT_FOUND)
}
}
async remove(id:string){
try{
const removePipelineResponse = await this.pipelineClient.remove({id});
return removePipelineResponse
}catch(err){
throw new HttpException(err.message,HttpStatus.NOT_FOUND)
}
}
async getPipelineLogsMessages(id:string,details:string){
try{
const pipelineLogsResponse = await this.pipelineClient.getPipelineLogsMessages({id,details});
return objectCamelToSnake(pipelineLogsResponse)
}catch(err){
throw new HttpException(err.message,HttpStatus.NOT_FOUND)
}
}
async getPipelineStatus(id:string){
try{
const pipelineStatusResponse = await this.pipelineClient.getPipelineStatus({id});
return objectCamelToSnake(pipelineStatusResponse)
}catch(err){
throw new HttpException(err.message,HttpStatus.NOT_FOUND)
}
}
}
@@ -1,83 +1,79 @@
// import {
// Body,
// Controller,
// Delete,
// Get,
// Param,
// Post,
// Put,
// Redirect,
// } from '@nestjs/common';
// import { Payload } from '@nestjs/microservices';
// import axios from 'axios';
// import { Console } from 'console';
// // import { CreateInputGrpcClientDto } from './dto/create-input-grpc-client.dto';
// // import { UpdateInputGrpcClientDto } from './dto/update-input-grpc-client.dto';
import {
Body,
Controller,
Delete,
Get,
Param,
Post,
Put,
Redirect,
} from '@nestjs/common';
import { Payload } from '@nestjs/microservices';
import { TransformationsClientService } from 'src/clients/transformations/client.service';
import { TransformationsService } from './transformations.service';
// @Controller('transformations')
// export class TransformationsController {
// @Get('/test-connection')
// async testConnection() {
// console.log(
// process.env.DEV_URL + `/test-connection`,
// 'ON TEST CONNECTION ROUTE',
// );
// await axios
// .get(process.env.DEV_URL + `/test-connection`)
// .then((response) => {
// return response;
// });
// }
@Controller('transformations')
export class TransformationsController {
// @Post()
// async create(@Body() createInputDto: CreateInputGrpcClientDto) {
// console.log(createInputDto);
// console.log(process.env.DEV_URL + `/input`, 'ON CREATE ROUTE');
constructor( private transformationsClientService:TransformationsClientService){}
// await axios
// .post(process.env.DEV_URL + '/input', createInputDto)
// .then((response) => {
// return response;
// });
// }
// @Get()
// async list() {
// console.log(process.env.DEV_URL + `/input`, 'ON GET ROUTE');
// await axios.get(process.env.DEV_URL + `/input`).then((response) => {
// return response;
// });
// }
// @Get('/:id')
// async show(@Param() id: string) {
// console.log(process.env.DEV_URL + `/input/${id}`, 'ON SHOW ROUTE');
// await axios.get(process.env.DEV_URL + `/input/${id}`).then((response) => {
// return response;
// });
// }
// @Put(':id')
// async update(
// @Payload() updateInputDto: UpdateInputGrpcClientDto,
// @Param() id: string,
// ) {
// console.log(process.env.DEV_URL + `/input/${id}`, 'ON UPDATE ROUTE');
// await axios
// .put(process.env.DEV_URL + `input/${id}`, updateInputDto)
// .then((response) => {
// return response;
// });
// }
// @Delete(':id')
// async delete(@Param() id: string) {
// console.log(process.env.DEV_URL + `/input/${id}`, 'ON DELETE ROUTE');
// await axios
// .delete(process.env.DEV_URL + `/input/${id}`)
// .then((response) => {
// return response;
// });
// }
// }
@Post()
async create(@Body() createTransformationDto) {
console.log(process.env.DEV_URL + `/transformation`, 'ON CREATE ROUTE');
const transformationService = new TransformationsService(this.transformationsClientService)
const response = await transformationService.create(createTransformationDto)
return response;
}
@Get()
async findAll() {
console.log(process.env.DEV_URL + `/transformation`, 'ON Find All ROUTE');
const transformationService = new TransformationsService(this.transformationsClientService)
const response = await transformationService.findAll()
return response;
}
@Get('/:id')
async findOne(@Param() params) {
const {id} = params;
console.log(process.env.DEV_URL + `/transformation/${id}`, 'ON Find One ROUTE');
const transformationService = new TransformationsService(this.transformationsClientService)
const response = await transformationService.findOne(id)
return response;
}
@Put(':id')
async update(
@Payload() updateTransformationDto,
@Param() params,
) {
const {id} = params;
console.log(process.env.DEV_URL + `/transformation/${id}`, 'ON UPDATE ROUTE');
const transformationService = new TransformationsService(this.transformationsClientService)
const response = await transformationService.update(id,updateTransformationDto)
return response;
}
@Delete(':id')
async delete(@Param() params) {
const {id} = params;
console.log(process.env.DEV_URL + `/transformation/${id}`, 'ON DELETE ROUTE');
const transformationService = new TransformationsService(this.transformationsClientService)
const response = await transformationService.remove(id)
return response;
}
}
@@ -1,8 +1,77 @@
import { Injectable } from '@nestjs/common';
import { HttpException, HttpStatus, Injectable } from '@nestjs/common';
import { TransformationsClientService } from 'src/clients/transformations/client.service';
import { ICreateTransformationsRequest } from 'src/clients/transformations/interfaces';
import { trSnakeToCamel } from 'src/utils/CaseConverter';
@Injectable()
export class TransformationsService {
check() {
return { message: 'Ok' };
constructor( private transformationClient: TransformationsClientService){}
async create(createTransformationDto:ICreateTransformationsRequest){
try{
let convertedDTO = createTransformationDto.transformations.map((tr)=>{
return trSnakeToCamel(tr)
})
const createTransformationResponse = await this.transformationClient.create({transformations:convertedDTO});
return createTransformationResponse
}catch(err){
throw new HttpException(err.message,HttpStatus.NOT_FOUND)
}
}
async findOne(id:string){
try{
const findOneTransformationResponse = await this.transformationClient.findOne({id});
return findOneTransformationResponse
}catch(err){
throw new HttpException(err.message,HttpStatus.NOT_FOUND)
}
}
async findAll(){
try{
const findAllTransformationResponse = await this.transformationClient.findAll();
return findAllTransformationResponse
}catch(err){
throw new HttpException(err.message,HttpStatus.NOT_FOUND)
}
}
async update(id:string, data){
try{
const updateTransformationResponse = await this.transformationClient.update({id,...data});
return updateTransformationResponse
}catch(err){
throw new HttpException(err.message,HttpStatus.NOT_FOUND)
}
}
async remove(id:string){
try{
const removeTransformationResponse = await this.transformationClient.remove({id});
return removeTransformationResponse
}catch(err){
throw new HttpException(err.message,HttpStatus.NOT_FOUND)
}
}
}
+64
View File
@@ -0,0 +1,64 @@
export const objectCamelToSnake = (object) => {
const objectKeys = Object.keys(object);
const objectValues = Object.values(object);
const newKeys = objectKeys.map((key) => {
return key
.split(/(?=[A-Z])/)
.join("_")
.toLowerCase();
});
objectKeys.forEach((key, index) => {
object[newKeys[index]] = object[key];
if (newKeys[index] !== objectKeys[index]) {
delete object[key];
}
});
objectValues.forEach((value) => {
if (typeof value === "object") {
objectCamelToSnake(value);
}
});
return object;
};
export const objectSnakeToCamel = (object) => {
const objectKeys = Object.keys(object);
const objectValues = Object.values(object);
const newKeys = objectKeys.map((key) => {
return key.replace(/([-_][a-z])/gi, ($1) => {
return $1.toUpperCase().replace("-", "").replace("_", "");
});
});
objectKeys.forEach((key, index) => {
object[newKeys[index]] = object[key];
if (newKeys[index] !== objectKeys[index]) {
delete object[key];
}
});
objectValues.forEach((value) => {
if (typeof value === "object") {
objectSnakeToCamel(value);
}
});
return object;
};
export const trSnakeToCamel = (object) =>{
const convertedParams = object.params.map((param)=>{
return objectSnakeToCamel(param)
})
object.params = convertedParams
return objectSnakeToCamel(object)
}
+1 -1
View File
@@ -1 +1 @@
{"openapi":"3.0.0","paths":{"/auth":{"post":{"operationId":"AuthController_signIn","parameters":[],"responses":{"201":{"description":""}}}},"/health":{"get":{"operationId":"HealthController_check","parameters":[],"responses":{"200":{"description":""}}}}},"info":{"title":"Maestro Grpc Documentation","description":"Documentation for Maestro gateway","version":"1.0","contact":{}},"tags":[],"servers":[],"components":{"securitySchemes":{"bearer":{"scheme":"bearer","bearerFormat":"JWT","type":"http"}},"schemas":{}}}
{"openapi":"3.0.0","paths":{"/input/test-connection":{"get":{"operationId":"InputsController_testConnection","parameters":[],"responses":{"200":{"description":""}}}},"/input":{"post":{"operationId":"InputsController_create","parameters":[],"responses":{"201":{"description":""}}},"get":{"operationId":"InputsController_findAll","parameters":[],"responses":{"200":{"description":""}}}},"/input/{id}":{"get":{"operationId":"InputsController_findOne","parameters":[],"responses":{"200":{"description":""}}},"put":{"operationId":"InputsController_update","parameters":[],"responses":{"200":{"description":""}}},"delete":{"operationId":"InputsController_delete","parameters":[],"responses":{"200":{"description":""}}}},"/transformations":{"post":{"operationId":"TransformationsController_create","parameters":[],"responses":{"201":{"description":""}}},"get":{"operationId":"TransformationsController_findAll","parameters":[],"responses":{"200":{"description":""}}}},"/transformations/{id}":{"get":{"operationId":"TransformationsController_findOne","parameters":[],"responses":{"200":{"description":""}}},"put":{"operationId":"TransformationsController_update","parameters":[],"responses":{"200":{"description":""}}},"delete":{"operationId":"TransformationsController_delete","parameters":[],"responses":{"200":{"description":""}}}},"/outputs":{"post":{"operationId":"OutputsController_create","parameters":[],"responses":{"201":{"description":""}}},"get":{"operationId":"OutputsController_findAll","parameters":[],"responses":{"200":{"description":""}}}},"/outputs/{id}":{"get":{"operationId":"OutputsController_findOne","parameters":[],"responses":{"200":{"description":""}}},"put":{"operationId":"OutputsController_update","parameters":[],"responses":{"200":{"description":""}}},"delete":{"operationId":"OutputsController_delete","parameters":[],"responses":{"200":{"description":""}}}},"/pipelines/{id}/status":{"get":{"operationId":"PipelinesController_getPipelineStatus","parameters":[],"responses":{"200":{"description":""}}}},"/pipelines/{id}/{details}":{"get":{"operationId":"PipelinesController_getPipelineLogs","parameters":[],"responses":{"200":{"description":""}}}},"/pipelines":{"post":{"operationId":"PipelinesController_create","parameters":[],"responses":{"201":{"description":""}}},"get":{"operationId":"PipelinesController_findAll","parameters":[],"responses":{"200":{"description":""}}}},"/pipelines/{id}":{"get":{"operationId":"PipelinesController_findOne","parameters":[],"responses":{"200":{"description":""}}},"put":{"operationId":"PipelinesController_update","parameters":[],"responses":{"200":{"description":""}}},"delete":{"operationId":"PipelinesController_delete","parameters":[],"responses":{"200":{"description":""}}}},"/auth":{"post":{"operationId":"AuthController_signIn","parameters":[],"responses":{"201":{"description":""}}}},"/health":{"get":{"operationId":"HealthController_check","parameters":[],"responses":{"200":{"description":""}}}}},"info":{"title":"Maestro Grpc Documentation","description":"Documentation for Maestro gateway","version":"1.0","contact":{}},"tags":[],"servers":[],"components":{"securitySchemes":{"bearer":{"scheme":"bearer","bearerFormat":"JWT","type":"http"}},"schemas":{}}}