mirror of
https://github.com/dadosfera/maestro.git
synced 2026-11-09 23:29:08 +00:00
implementing transformation module on gateway
This commit is contained in:
+2
-1
@@ -3,11 +3,12 @@ import { InputGrpcClientModule } from './inputs/input-grpc-client.module';
|
||||
import { UsersGrpcClientModule } from './users-grpc-client/users-grpc-client.module';
|
||||
import { OutputsModule } from './outputs/outputs.module';
|
||||
import { EnrichmentModule } from './enrichment/enrichment.module';
|
||||
import { TransformationsModule } from './transformations/transformations.module';
|
||||
|
||||
@Module({
|
||||
imports: [
|
||||
InputGrpcClientModule,
|
||||
OutputsModule, EnrichmentModule
|
||||
OutputsModule, EnrichmentModule, TransformationsModule
|
||||
],
|
||||
controllers: [],
|
||||
providers: [],
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { Controller, Delete, Get, Param, Post, Put } from '@nestjs/common';
|
||||
import { Controller, Delete, Get, OnModuleInit, Param, Post, Put } from '@nestjs/common';
|
||||
import { Client, ClientGrpc, Payload } from '@nestjs/microservices';
|
||||
import { EnrichmentGrpcClientService } from './enrichment.service';
|
||||
import { CreateEnrichmentDto } from './dto/create-enrichment.dto';
|
||||
@@ -8,7 +8,7 @@ import { GrpcClientConfiguration } from './config/grpc-client';
|
||||
|
||||
@ApiTags('enrichments')
|
||||
@Controller('enrichment')
|
||||
export class EnrichmentController {
|
||||
export class EnrichmentController implements OnModuleInit {
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
import { join } from 'path';
|
||||
import { ClientOptions, Transport } from '@nestjs/microservices';
|
||||
|
||||
export const GrpcClientConfiguration: 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,
|
||||
},
|
||||
},
|
||||
};
|
||||
@@ -0,0 +1,11 @@
|
||||
|
||||
|
||||
export class CreateTransformationDto {
|
||||
inputSource:string;
|
||||
|
||||
table:string;
|
||||
|
||||
type:string;
|
||||
|
||||
params:string;
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
import { PartialType } from '@nestjs/mapped-types';
|
||||
import { CreateTransformationDto } from './create-transformation.dto';
|
||||
|
||||
export class UpdateTransformationDto extends PartialType(CreateTransformationDto) {
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
export class Transformation {
|
||||
|
||||
id:string;
|
||||
|
||||
inputSource:string;
|
||||
|
||||
table:string;
|
||||
|
||||
type:string;
|
||||
|
||||
params:string;
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
syntax = "proto3";
|
||||
|
||||
package transformation;
|
||||
|
||||
|
||||
import "google/protobuf/timestamp.proto";
|
||||
|
||||
|
||||
|
||||
service TransformationService {
|
||||
rpc Create(CreateTransformationRequest) returns (Transformation) {}
|
||||
rpc Show(IdRequest) returns (Transformation) {}
|
||||
rpc List(Empty) returns (ListResponse){}
|
||||
rpc Update(UpdateTransformationRequest) returns (Transformation){}
|
||||
rpc Remove(IdRequest) returns (Empty){}
|
||||
}
|
||||
|
||||
message Empty {}
|
||||
|
||||
message IdRequest{
|
||||
string id = 1;
|
||||
}
|
||||
|
||||
message UpdateTransformationRequest{
|
||||
string id = 1;
|
||||
string inputSource = 2;
|
||||
string table = 3;
|
||||
string type = 4;
|
||||
string params = 5;
|
||||
}
|
||||
|
||||
message Transformation {
|
||||
string id = 1;
|
||||
string inputSource = 2;
|
||||
string table = 3;
|
||||
string type = 4;
|
||||
string params = 5;
|
||||
}
|
||||
|
||||
message CreateTransformationRequest {
|
||||
string inputSource = 1;
|
||||
string table = 2;
|
||||
string type = 3;
|
||||
string params = 4;
|
||||
}
|
||||
|
||||
message ListResponse {
|
||||
repeated Transformation transformations = 2;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
import { Test, TestingModule } from '@nestjs/testing';
|
||||
import { TransformationsController } from './transformations.controller';
|
||||
import { TransformationGrpcClientService } from './transformations.service';
|
||||
|
||||
describe('TransformationsController', () => {
|
||||
let controller: TransformationsController;
|
||||
|
||||
beforeEach(async () => {
|
||||
const module: TestingModule = await Test.createTestingModule({
|
||||
controllers: [TransformationsController],
|
||||
providers: [TransformationGrpcClientService],
|
||||
}).compile();
|
||||
|
||||
controller = module.get<TransformationsController>(TransformationsController);
|
||||
});
|
||||
|
||||
it('should be defined', () => {
|
||||
expect(controller).toBeDefined();
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,48 @@
|
||||
import { Controller, Delete, Get, OnModuleInit, Param, Post, Put } from '@nestjs/common';
|
||||
import { Client, ClientGrpc, MessagePattern, Payload } from '@nestjs/microservices';
|
||||
import { TransformationGrpcClientService } 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 './config/grpc-client';
|
||||
|
||||
@ApiTags('transformations')
|
||||
@Controller('transformation')
|
||||
export class TransformationsController implements OnModuleInit {
|
||||
|
||||
@Client(GrpcClientConfiguration)
|
||||
private transformationServiceClient: ClientGrpc;
|
||||
|
||||
private transformationService: TransformationGrpcClientService;
|
||||
|
||||
onModuleInit() {
|
||||
this.transformationService =
|
||||
this.transformationServiceClient.getService<TransformationGrpcClientService>('TransformationService');
|
||||
}
|
||||
|
||||
@Post()
|
||||
create(@Payload() createTransformationDto: CreateTransformationDto[]) {
|
||||
|
||||
return createTransformationDto.map( transf => this.transformationService.create(transf))
|
||||
}
|
||||
|
||||
@Get()
|
||||
list() {
|
||||
return this.transformationService.list();
|
||||
}
|
||||
|
||||
@Get(':id')
|
||||
show(@Payload() id: string) {
|
||||
return this.transformationService.show(id);
|
||||
}
|
||||
|
||||
@Put(':id')
|
||||
update(@Param() id:string,@Payload() updateTransformationDto: UpdateTransformationDto) {
|
||||
return this.transformationService.update(id, updateTransformationDto);
|
||||
}
|
||||
|
||||
@Delete(':id')
|
||||
remove(@Param() id: string) {
|
||||
return this.transformationService.remove(id);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
import { Module } from '@nestjs/common';
|
||||
import { TransformationGrpcClientService } from './transformations.service';
|
||||
import { TransformationsController } from './transformations.controller';
|
||||
|
||||
@Module({
|
||||
controllers: [TransformationsController],
|
||||
providers: [TransformationGrpcClientService]
|
||||
})
|
||||
export class TransformationsModule {}
|
||||
@@ -0,0 +1,18 @@
|
||||
import { Test, TestingModule } from '@nestjs/testing';
|
||||
import { TransformationsService } from './transformations.service';
|
||||
|
||||
describe('TransformationsService', () => {
|
||||
let service: TransformationsService;
|
||||
|
||||
beforeEach(async () => {
|
||||
const module: TestingModule = await Test.createTestingModule({
|
||||
providers: [TransformationsService],
|
||||
}).compile();
|
||||
|
||||
service = module.get<TransformationsService>(TransformationsService);
|
||||
});
|
||||
|
||||
it('should be defined', () => {
|
||||
expect(service).toBeDefined();
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,26 @@
|
||||
import { Injectable } from '@nestjs/common';
|
||||
import { CreateTransformationDto } from './dto/create-transformation.dto';
|
||||
import { UpdateTransformationDto } from './dto/update-transformation.dto';
|
||||
|
||||
@Injectable()
|
||||
export class TransformationGrpcClientService {
|
||||
create(createTransformationDto: CreateTransformationDto) {
|
||||
return 'This action adds a new transformation';
|
||||
}
|
||||
|
||||
list() {
|
||||
return `This action returns all transformations`;
|
||||
}
|
||||
|
||||
show(id: string) {
|
||||
return `This action returns a #${id} transformation`;
|
||||
}
|
||||
|
||||
update(id: string, updateTransformationDto: UpdateTransformationDto) {
|
||||
return `This action updates a #${id} transformation`;
|
||||
}
|
||||
|
||||
remove(id: string) {
|
||||
return `This action removes a #${id} transformation`;
|
||||
}
|
||||
}
|
||||
+1
-1
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user