mirror of
https://github.com/dadosfera/maestro.git
synced 2026-11-26 05:10:06 +00:00
FEAT: Pipeline Version 2
This commit is contained in:
Generated
+7
-7
@@ -12,7 +12,7 @@
|
||||
"dependencies": {
|
||||
"@aws-sdk/client-secrets-manager": "^3.112.0",
|
||||
"@dadosfera/dadosfera-logs": "^1.0.0-beta.3",
|
||||
"@dadosfera/protospack-v2": "^3.13.0",
|
||||
"@dadosfera/protospack-v2": "^3.14.8",
|
||||
"@grpc/grpc-js": "^1.6.7",
|
||||
"@grpc/proto-loader": "^0.6.13",
|
||||
"@nestjs/common": "^8.4.7",
|
||||
@@ -1726,9 +1726,9 @@
|
||||
}
|
||||
},
|
||||
"node_modules/@dadosfera/protospack-v2": {
|
||||
"version": "3.13.0",
|
||||
"resolved": "https://dadosfera-611330257153.d.codeartifact.us-east-1.amazonaws.com:443/npm/dadosfera-npm/@dadosfera/protospack-v2/-/protospack-v2-3.13.0.tgz",
|
||||
"integrity": "sha512-MVTBvt+7rXpZ9uRPB6SF8z2wubMIYmB66krCIe3xqrdnLvtAkLc9mrJ20qMmQ6hkx5k+iMux/IJTL0IihLuEjA==",
|
||||
"version": "3.14.8",
|
||||
"resolved": "https://dadosfera-611330257153.d.codeartifact.us-east-1.amazonaws.com:443/npm/dadosfera-npm/@dadosfera/protospack-v2/-/protospack-v2-3.14.8.tgz",
|
||||
"integrity": "sha512-tVkNjLn0EKTEKJXD+qM+4QxgyVuQYannhc49FNpy0iwM82HS3jK7ZEY4e4g5oTQG16VuysqlTyGRV/CNKgR7ig==",
|
||||
"dependencies": {
|
||||
"@grpc/grpc-js": "^1.6.7",
|
||||
"rxjs": "^7.5.5",
|
||||
@@ -12297,9 +12297,9 @@
|
||||
}
|
||||
},
|
||||
"@dadosfera/protospack-v2": {
|
||||
"version": "3.13.0",
|
||||
"resolved": "https://dadosfera-611330257153.d.codeartifact.us-east-1.amazonaws.com:443/npm/dadosfera-npm/@dadosfera/protospack-v2/-/protospack-v2-3.13.0.tgz",
|
||||
"integrity": "sha512-MVTBvt+7rXpZ9uRPB6SF8z2wubMIYmB66krCIe3xqrdnLvtAkLc9mrJ20qMmQ6hkx5k+iMux/IJTL0IihLuEjA==",
|
||||
"version": "3.14.8",
|
||||
"resolved": "https://dadosfera-611330257153.d.codeartifact.us-east-1.amazonaws.com:443/npm/dadosfera-npm/@dadosfera/protospack-v2/-/protospack-v2-3.14.8.tgz",
|
||||
"integrity": "sha512-tVkNjLn0EKTEKJXD+qM+4QxgyVuQYannhc49FNpy0iwM82HS3jK7ZEY4e4g5oTQG16VuysqlTyGRV/CNKgR7ig==",
|
||||
"requires": {
|
||||
"@grpc/grpc-js": "^1.6.7",
|
||||
"rxjs": "^7.5.5",
|
||||
|
||||
+1
-1
@@ -27,7 +27,7 @@
|
||||
"dependencies": {
|
||||
"@aws-sdk/client-secrets-manager": "^3.112.0",
|
||||
"@dadosfera/dadosfera-logs": "^1.0.0-beta.3",
|
||||
"@dadosfera/protospack-v2": "^3.13.0",
|
||||
"@dadosfera/protospack-v2": "^3.14.8",
|
||||
"@grpc/grpc-js": "^1.6.7",
|
||||
"@grpc/proto-loader": "^0.6.13",
|
||||
"@nestjs/common": "^8.4.7",
|
||||
|
||||
@@ -22,6 +22,7 @@ import { TransformationsModule } from './modules/transformations/transformations
|
||||
import { HealthModule } from './modules/health/health.module';
|
||||
import { CatalogModule } from './modules/catalog/catalog.module';
|
||||
import { ConfigModule } from '@nestjs/config';
|
||||
import { PipelinesV2Module } from './modules/pipelinesV2/pipelines.module';
|
||||
|
||||
@Module({
|
||||
controllers: [],
|
||||
@@ -51,6 +52,7 @@ import { ConfigModule } from '@nestjs/config';
|
||||
RolesModule,
|
||||
InputsModule,
|
||||
OauthModule,
|
||||
PipelinesV2Module,
|
||||
],
|
||||
})
|
||||
export class AppModule {}
|
||||
|
||||
@@ -20,6 +20,7 @@ import {
|
||||
DatabaseConnectionPropertiesDto,
|
||||
} from '../connection/dtos/connection';
|
||||
import { RequestUser } from 'src/authentication/user.decorator';
|
||||
import { PackTheMetadata } from 'src/utils/ PackTheMetadata';
|
||||
|
||||
@Injectable()
|
||||
export class ConnectionTestService {
|
||||
@@ -62,7 +63,13 @@ export class ConnectionTestService {
|
||||
): Promise<ConnectionTestCredentialsRes> {
|
||||
const { plugin, ...connectionBody } = body;
|
||||
let { connection_id } = body;
|
||||
const { customer_id, customer_name, user_id } = user;
|
||||
const { customer_id, customer_name, user_id, username } = user;
|
||||
const metadata = PackTheMetadata({
|
||||
customer_id,
|
||||
customer_name,
|
||||
user_id,
|
||||
username,
|
||||
});
|
||||
|
||||
/********* CREATE CONNECTION *********/
|
||||
if (!connection_id) {
|
||||
@@ -91,14 +98,14 @@ export class ConnectionTestService {
|
||||
).catch(async (e) => {
|
||||
await this.connectionsService.deleteConnection({
|
||||
body: { id: connection_id },
|
||||
info: { customer_id, customer_name, user_id },
|
||||
metadata,
|
||||
});
|
||||
throw e;
|
||||
});
|
||||
if (!operation_result) {
|
||||
await this.connectionsService.deleteConnection({
|
||||
body: { id: connection_id },
|
||||
info: { customer_id, customer_name, user_id },
|
||||
metadata,
|
||||
});
|
||||
connection_id = null;
|
||||
}
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
import { Metadata } from '@grpc/grpc-js';
|
||||
import {
|
||||
OnModuleInit,
|
||||
Inject,
|
||||
@@ -39,13 +38,8 @@ export class ConnectionClientService implements OnModuleInit {
|
||||
|
||||
async createConnection(
|
||||
body: CreateConnectionDto,
|
||||
info: any,
|
||||
metadata,
|
||||
): Promise<ConnectionRes> {
|
||||
const meta = new Metadata();
|
||||
meta.add('customer_id', info.customer_id);
|
||||
meta.add('customer_name', info.customer_name);
|
||||
meta.add('user_id', info.user_id);
|
||||
|
||||
const {
|
||||
connector_id,
|
||||
description,
|
||||
@@ -69,7 +63,7 @@ export class ConnectionClientService implements OnModuleInit {
|
||||
properties: JSON.stringify(properties),
|
||||
type,
|
||||
},
|
||||
meta,
|
||||
metadata,
|
||||
),
|
||||
).catch((err) => {
|
||||
throw new HttpException(
|
||||
@@ -82,14 +76,8 @@ export class ConnectionClientService implements OnModuleInit {
|
||||
async updateConnection(
|
||||
id: string,
|
||||
body: UpdateConnectionDto,
|
||||
info,
|
||||
metadata,
|
||||
): Promise<ConnectionRes> {
|
||||
const meta = new Metadata();
|
||||
meta.add('customer_id', info.customer_id);
|
||||
meta.add('customer_name', info.customer_name);
|
||||
meta.add('user_id', info.user_id);
|
||||
meta.add('language', info.language);
|
||||
|
||||
const { description, name, network_config_id, properties } = body;
|
||||
|
||||
return lastValueFrom(
|
||||
@@ -101,7 +89,7 @@ export class ConnectionClientService implements OnModuleInit {
|
||||
network_config_id,
|
||||
properties: JSON.stringify(properties),
|
||||
},
|
||||
meta,
|
||||
metadata,
|
||||
),
|
||||
).catch((err) => {
|
||||
throw new HttpException(
|
||||
@@ -111,12 +99,7 @@ export class ConnectionClientService implements OnModuleInit {
|
||||
});
|
||||
}
|
||||
|
||||
async deleteConnection({ body, info }): Promise<ConnectionRes> {
|
||||
const meta = new Metadata();
|
||||
meta.add('customer_id', info.customer_id);
|
||||
meta.add('customer_name', info.customer_name);
|
||||
meta.add('user_id', info.user_id);
|
||||
|
||||
async deleteConnection({ body, metadata }): Promise<ConnectionRes> {
|
||||
const { id } = body;
|
||||
|
||||
return lastValueFrom(
|
||||
@@ -124,7 +107,7 @@ export class ConnectionClientService implements OnModuleInit {
|
||||
{
|
||||
id,
|
||||
},
|
||||
meta,
|
||||
metadata,
|
||||
),
|
||||
).catch((err) => {
|
||||
throw new HttpException(
|
||||
@@ -134,19 +117,13 @@ export class ConnectionClientService implements OnModuleInit {
|
||||
});
|
||||
}
|
||||
|
||||
async getAllConnection({ body, info }): Promise<ConnectionsRes> {
|
||||
const meta = new Metadata();
|
||||
meta.add('customer_id', info.customer_id);
|
||||
meta.add('customer_name', info.customer_name);
|
||||
meta.add('user_id', info.user_id);
|
||||
meta.add('language', info.language);
|
||||
|
||||
async getAllConnection({ body, metadata }): Promise<ConnectionsRes> {
|
||||
const { search, filters, size, page } = body;
|
||||
|
||||
return lastValueFrom(
|
||||
this.connectionServiceRead.GetAllConnection(
|
||||
{ search, filters: JSON.stringify(filters), size, page },
|
||||
meta,
|
||||
metadata,
|
||||
),
|
||||
).catch((err) => {
|
||||
throw new HttpException(
|
||||
@@ -156,39 +133,14 @@ export class ConnectionClientService implements OnModuleInit {
|
||||
});
|
||||
}
|
||||
|
||||
async getConnection({ body, info }): Promise<ConnectionRes> {
|
||||
const meta = new Metadata();
|
||||
meta.add('customer_id', info.customer_id);
|
||||
meta.add('customer_name', info.customer_name);
|
||||
meta.add('user_id', info.user_id);
|
||||
meta.add('language', info.language);
|
||||
|
||||
const { id } = body;
|
||||
|
||||
return lastValueFrom(
|
||||
this.connectionServiceRead.GetConnection({ id }, meta),
|
||||
).catch((err) => {
|
||||
throw new HttpException(
|
||||
err.details,
|
||||
err.code === 6 ? HttpStatus.CONFLICT : 400,
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
async getConnectionDetails({
|
||||
body,
|
||||
info,
|
||||
metadata,
|
||||
}): Promise<GetConnectionDetailsResponse> {
|
||||
const meta = new Metadata();
|
||||
meta.add('customer_id', info.customer_id);
|
||||
meta.add('customer_name', info.customer_name);
|
||||
meta.add('user_id', info.user_id);
|
||||
meta.add('details', info.details);
|
||||
|
||||
const { id } = body;
|
||||
|
||||
return lastValueFrom(
|
||||
this.connectionServiceRead.GetConnectionDetails({ id }, meta),
|
||||
this.connectionServiceRead.GetConnectionDetails({ id }, metadata),
|
||||
).catch((err) => {
|
||||
throw new HttpException(
|
||||
err.details,
|
||||
|
||||
@@ -18,7 +18,7 @@ import {
|
||||
RequireAllPermissions,
|
||||
} from 'src/authentication/authentication.decorator';
|
||||
import { PERMISSIONS } from 'src/authentication/permissions.enum';
|
||||
import { User } from 'src/authentication/user.decorator';
|
||||
import { RequestUser, User } from 'src/authentication/user.decorator';
|
||||
import { ValidationPipe } from '../../pipes/object-validation.pipe';
|
||||
import {
|
||||
ConnectionDetailsRes,
|
||||
@@ -27,6 +27,7 @@ import {
|
||||
UpdateConnectionDto,
|
||||
} from './dtos/connection';
|
||||
import { CreateConnectionDto } from './dtos/connection';
|
||||
import { PackTheMetadata } from 'src/utils/ PackTheMetadata';
|
||||
|
||||
@ApiTags('connections')
|
||||
@ApiBearerAuth()
|
||||
@@ -45,57 +46,74 @@ export class ConnectionController {
|
||||
@Post()
|
||||
// @RequireAllPermissions(Permissions.CONNECTIONS.CREATE)
|
||||
async createConnection(
|
||||
@User() user,
|
||||
@User() user: RequestUser,
|
||||
@Body(new ValidationPipe()) body: CreateConnectionDto,
|
||||
): Promise<ConnectionRes> {
|
||||
this.logger.info('/connections - Create Connection');
|
||||
|
||||
const { user_id, customer_id, customer_name } = user;
|
||||
|
||||
const response: any = await this.clientService.createConnection(body, {
|
||||
const { user_id, customer_id, customer_name, username } = user;
|
||||
const metadata = PackTheMetadata({
|
||||
user_id,
|
||||
customer_id,
|
||||
customer_name,
|
||||
username,
|
||||
});
|
||||
|
||||
const response: any = await this.clientService.createConnection(
|
||||
body,
|
||||
metadata,
|
||||
);
|
||||
|
||||
return response;
|
||||
}
|
||||
|
||||
@Put('/:id')
|
||||
// @RequireAllPermissions(Permissions.CONNECTIONS.CREATE)
|
||||
async updateConnection(
|
||||
@User() user,
|
||||
@User() user: RequestUser,
|
||||
@Headers('Dadosfera-Lang') language: string,
|
||||
@Param('id') id: string,
|
||||
@Body(new ValidationPipe()) body: UpdateConnectionDto,
|
||||
): Promise<ConnectionRes> {
|
||||
this.logger.info('/connections - Update Connection');
|
||||
|
||||
const { user_id, customer_id, customer_name } = user;
|
||||
|
||||
const response: any = await this.clientService.updateConnection(id, body, {
|
||||
const { user_id, customer_id, customer_name, username } = user;
|
||||
const metadata = PackTheMetadata({
|
||||
user_id,
|
||||
customer_id,
|
||||
customer_name,
|
||||
language,
|
||||
username,
|
||||
});
|
||||
|
||||
const response: any = await this.clientService.updateConnection(
|
||||
id,
|
||||
body,
|
||||
metadata,
|
||||
);
|
||||
|
||||
return response;
|
||||
}
|
||||
|
||||
@Delete('/:id')
|
||||
// @RequireAllPermissions(Permissions.CONNECTIONS.CREATE)
|
||||
async deleteConnection(
|
||||
@User() user,
|
||||
@User() user: RequestUser,
|
||||
@Param('id') id: string,
|
||||
): Promise<ConnectionRes> {
|
||||
this.logger.info('/connections - Delete Connection');
|
||||
|
||||
const { user_id, customer_id, customer_name } = user;
|
||||
const { user_id, customer_id, customer_name, username } = user;
|
||||
const metadata = PackTheMetadata({
|
||||
user_id,
|
||||
customer_id,
|
||||
customer_name,
|
||||
username,
|
||||
});
|
||||
|
||||
const response: any = await this.clientService.deleteConnection({
|
||||
body: { id },
|
||||
info: { user_id, customer_id, customer_name },
|
||||
metadata,
|
||||
});
|
||||
|
||||
return response;
|
||||
@@ -104,18 +122,25 @@ export class ConnectionController {
|
||||
@Get()
|
||||
// @RequireAllPermissions(Permissions.CONNECTIONS.CREATE)
|
||||
async getAllConnection(
|
||||
@User() user,
|
||||
@User() user: RequestUser,
|
||||
@Headers('Dadosfera-Lang') language,
|
||||
@Query() queries,
|
||||
): Promise<ConnectionsRes> {
|
||||
this.logger.info('/connections - Get All Connection');
|
||||
|
||||
const { user_id, customer_id, customer_name } = user;
|
||||
const { user_id, customer_id, customer_name, username } = user;
|
||||
const { search, size, page, ...filters } = queries;
|
||||
const metadata = PackTheMetadata({
|
||||
user_id,
|
||||
customer_id,
|
||||
customer_name,
|
||||
language,
|
||||
username,
|
||||
});
|
||||
|
||||
const response = await this.clientService.getAllConnection({
|
||||
body: { search, size, page, filters },
|
||||
info: { user_id, customer_id, customer_name, language },
|
||||
metadata,
|
||||
});
|
||||
|
||||
return response;
|
||||
@@ -124,17 +149,24 @@ export class ConnectionController {
|
||||
@Get('/:id')
|
||||
// @RequireAllPermissions(Permissions.CONNECTIONS.CREATE)
|
||||
async getConnectionDetails(
|
||||
@User() user,
|
||||
@User() user: RequestUser,
|
||||
@Param('id') id,
|
||||
@Query('details') details,
|
||||
): Promise<ConnectionDetailsRes> {
|
||||
this.logger.info('/connections - Get Connection Details');
|
||||
|
||||
const { user_id, customer_id, customer_name } = user;
|
||||
const { user_id, customer_id, customer_name, username } = user;
|
||||
const metadata = PackTheMetadata({
|
||||
user_id,
|
||||
customer_id,
|
||||
customer_name,
|
||||
username,
|
||||
details,
|
||||
});
|
||||
|
||||
const response: any = await this.clientService.getConnectionDetails({
|
||||
body: { id },
|
||||
info: { user_id, customer_id, customer_name, details },
|
||||
metadata,
|
||||
});
|
||||
|
||||
if (details === 'true') {
|
||||
|
||||
+36
@@ -0,0 +1,36 @@
|
||||
import { Info } from 'protospack/dist/lib/interfaces';
|
||||
|
||||
export interface ICreatePipelineDto {
|
||||
input: IdRequest;
|
||||
transformations: IdRequest[];
|
||||
output: IdRequest;
|
||||
tags: string[];
|
||||
name: string;
|
||||
description: string;
|
||||
info: Info;
|
||||
}
|
||||
|
||||
export interface IdRequest {
|
||||
id: string;
|
||||
}
|
||||
|
||||
export interface IIdRequest {
|
||||
id: string;
|
||||
info: Info;
|
||||
}
|
||||
|
||||
export interface IUpdatePipelineRequest {
|
||||
input: IdRequest;
|
||||
transformations: IdRequest[];
|
||||
output: IdRequest;
|
||||
tags: string[];
|
||||
name: string;
|
||||
description: string;
|
||||
id: string;
|
||||
info: Info;
|
||||
}
|
||||
|
||||
export interface IGetPipelineLogsRequest {
|
||||
id: string;
|
||||
details: string;
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
import {
|
||||
ClientsProviderAsyncOptions,
|
||||
GrpcOptions,
|
||||
Transport,
|
||||
} from '@nestjs/microservices';
|
||||
import {
|
||||
ProtoPackages,
|
||||
ProtoPaths,
|
||||
} from '@dadosfera/protospack-v2/dist/lib/PipelineV2';
|
||||
import { credentials } from '@grpc/grpc-js';
|
||||
|
||||
export class PipelinesClientConfiguration {
|
||||
public name = 'PipelinesClientConfiguration';
|
||||
private config: GrpcOptions = {
|
||||
transport: Transport.GRPC,
|
||||
options: {
|
||||
url: process.env.PIFACTORY_URL,
|
||||
package: [ProtoPackages.ReadPackage, ProtoPackages.WritePackage],
|
||||
credentials:
|
||||
process.env.LOCAL_ENV || process.env.ENV === 'local'
|
||||
? undefined
|
||||
: credentials.createSsl(),
|
||||
protoPath: [ProtoPaths.ReadFilePath, ProtoPaths.WriteFilePath],
|
||||
loader: {
|
||||
enums: String,
|
||||
objects: true,
|
||||
arrays: true,
|
||||
},
|
||||
},
|
||||
};
|
||||
providerOptions: ClientsProviderAsyncOptions = {
|
||||
name: this.name,
|
||||
...this.config,
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,108 @@
|
||||
import {
|
||||
Body,
|
||||
Controller,
|
||||
Delete,
|
||||
Get,
|
||||
Inject,
|
||||
Param,
|
||||
Post,
|
||||
Put,
|
||||
} from '@nestjs/common';
|
||||
import { ApiTags } from '@nestjs/swagger';
|
||||
import { AuthenticateCondition } from 'src/authentication/authentication.decorator';
|
||||
import { PERMISSIONS } from '../../authentication/permissions.enum';
|
||||
import { PipelinesService } from './pipelines.service';
|
||||
import { DadosferaLogger } from '@dadosfera/dadosfera-logs';
|
||||
import { Messages } from '@dadosfera/protospack-v2/dist/lib/PipelineV2';
|
||||
|
||||
@ApiTags('Pipelines')
|
||||
@Controller('pipelinesV2')
|
||||
@AuthenticateCondition((req, user) => {
|
||||
let action;
|
||||
|
||||
switch (req.method) {
|
||||
case 'POST':
|
||||
action = 'CREATE';
|
||||
break;
|
||||
|
||||
case 'PUT':
|
||||
action = 'UPDATE';
|
||||
break;
|
||||
|
||||
default:
|
||||
action = req.method;
|
||||
}
|
||||
|
||||
return user.permissions.includes(
|
||||
PERMISSIONS.PIPELINE.permissions[action].seqid,
|
||||
);
|
||||
})
|
||||
export class PipelinesController {
|
||||
logger: DadosferaLogger;
|
||||
constructor(
|
||||
@Inject(DadosferaLogger)
|
||||
dadosferaLogger: DadosferaLogger,
|
||||
private pipelinesClientService: PipelinesService,
|
||||
) {
|
||||
this.logger = dadosferaLogger.logger;
|
||||
}
|
||||
|
||||
@Post()
|
||||
async create(@Body() createPipelineDto: Messages.PipelineV2CreateRequest) {
|
||||
this.logger.info(process.env.DEV_URL + `/pipelines ON CREATE ROUTE`);
|
||||
|
||||
const response = await this.pipelinesClientService.create(
|
||||
createPipelineDto,
|
||||
);
|
||||
|
||||
return response;
|
||||
}
|
||||
|
||||
@Get()
|
||||
async findAll(@Body() data) {
|
||||
this.logger.info(process.env.DEV_URL + `/pipeline ON Find All ROUTE`, {
|
||||
user: data.info.user_id,
|
||||
customer: data.info.customer,
|
||||
});
|
||||
|
||||
const response = await this.pipelinesClientService.findAll(data);
|
||||
|
||||
return response;
|
||||
}
|
||||
|
||||
@Get('/:id')
|
||||
async findOne(@Body() data, @Param() params) {
|
||||
const { id } = params;
|
||||
this.logger.info(process.env.DEV_URL + `/pipeline/${id} ON Find One ROUTE`);
|
||||
|
||||
const response = await this.pipelinesClientService.findOne({ id, ...data });
|
||||
|
||||
return response;
|
||||
}
|
||||
|
||||
@Put('/:id')
|
||||
async update(@Body() updatePipelineDto, @Param('id') id) {
|
||||
const { info } = updatePipelineDto;
|
||||
delete updatePipelineDto.info;
|
||||
|
||||
this.logger.info(process.env.DEV_URL + `/pipeline/${id} ON UPDATE ROUTE`);
|
||||
|
||||
const response = await this.pipelinesClientService.update({
|
||||
...updatePipelineDto,
|
||||
info,
|
||||
id,
|
||||
});
|
||||
|
||||
return response;
|
||||
}
|
||||
|
||||
@Delete(':id')
|
||||
async delete(@Body() data, @Param() params) {
|
||||
const { id } = params;
|
||||
this.logger.info(process.env.DEV_URL + `/pipeline/${id} ON DELETE ROUTE`);
|
||||
|
||||
const response = await this.pipelinesClientService.remove({ id, ...data });
|
||||
|
||||
return response;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
import { Module } from '@nestjs/common';
|
||||
import { ClientsModule } from '@nestjs/microservices';
|
||||
import { DadosferaLogger } from '@dadosfera/dadosfera-logs';
|
||||
|
||||
import { PipelinesController } from './pipelines.controller';
|
||||
import { PipelinesService } from './pipelines.service';
|
||||
|
||||
import { PipelinesClientConfiguration } from './pipelines-client';
|
||||
|
||||
const client = new PipelinesClientConfiguration();
|
||||
|
||||
@Module({
|
||||
imports: [ClientsModule.register([client.providerOptions])],
|
||||
controllers: [PipelinesController],
|
||||
providers: [PipelinesService, DadosferaLogger],
|
||||
exports: [PipelinesService],
|
||||
})
|
||||
export class PipelinesV2Module {}
|
||||
@@ -0,0 +1,135 @@
|
||||
import {
|
||||
BadRequestException,
|
||||
Inject,
|
||||
InternalServerErrorException,
|
||||
OnModuleInit,
|
||||
} from '@nestjs/common';
|
||||
import { ClientGrpc, Payload } from '@nestjs/microservices';
|
||||
import {
|
||||
Messages,
|
||||
WriteService,
|
||||
ReadService,
|
||||
ProtoServices,
|
||||
} from '@dadosfera/protospack-v2/dist/lib/PipelineV2';
|
||||
import { lastValueFrom } from 'rxjs';
|
||||
|
||||
import { DadosferaLogger } from '@dadosfera/dadosfera-logs';
|
||||
import { PipelinesClientConfiguration } from './pipelines-client';
|
||||
|
||||
export class PipelinesService implements OnModuleInit {
|
||||
logger: DadosferaLogger;
|
||||
pipelineWriteService: WriteService.PipelineV2WriteService;
|
||||
pipelineReadService: ReadService.PipelineV2ReadService;
|
||||
constructor(
|
||||
@Inject(DadosferaLogger)
|
||||
dadosferaLogger: DadosferaLogger,
|
||||
@Inject(PipelinesClientConfiguration.name)
|
||||
private readonly grpcClient: ClientGrpc,
|
||||
) {
|
||||
this.logger = dadosferaLogger.logger;
|
||||
}
|
||||
|
||||
onModuleInit() {
|
||||
this.pipelineReadService =
|
||||
this.grpcClient.getService<ReadService.PipelineV2ReadService>(
|
||||
ProtoServices.PipelineV2ReadService,
|
||||
);
|
||||
|
||||
this.pipelineWriteService =
|
||||
this.grpcClient.getService<WriteService.PipelineV2WriteService>(
|
||||
ProtoServices.PipelineV2WriteService,
|
||||
);
|
||||
}
|
||||
|
||||
async create(@Payload() createPipelineDto: Messages.PipelineV2CreateRequest) {
|
||||
this.logger.info('PipelinesClientService - Create');
|
||||
const createPipelineResponse = await lastValueFrom(
|
||||
this.pipelineWriteService.PipelineV2Create(createPipelineDto),
|
||||
)
|
||||
.then((res) => {
|
||||
this.logger.info('Done');
|
||||
return res;
|
||||
})
|
||||
.catch((error: { details: string }) => {
|
||||
if (error.details.includes('INVALID_REQUEST')) {
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
const [errorType, message] = error.details.split('|');
|
||||
throw new BadRequestException(message);
|
||||
}
|
||||
throw new InternalServerErrorException(error.details);
|
||||
});
|
||||
|
||||
return createPipelineResponse;
|
||||
}
|
||||
|
||||
async findAll(data: Messages.PipelineV2FindAllRequest) {
|
||||
this.logger.info('PipelinesClientService - FindAll');
|
||||
const findAllPipelineResponse = await lastValueFrom(
|
||||
this.pipelineReadService.PipelineV2FindAll(data),
|
||||
)
|
||||
.then((res) => {
|
||||
this.logger.info('Done');
|
||||
return res;
|
||||
})
|
||||
.catch((err) => {
|
||||
this.logger.error(err.message);
|
||||
throw new Error(err);
|
||||
});
|
||||
|
||||
return findAllPipelineResponse;
|
||||
}
|
||||
|
||||
async findOne(data: Messages.PipelineV2FindOneRequest) {
|
||||
this.logger.info('PipelinesClientService - FindOne');
|
||||
|
||||
const findOnePipelineResponse = await lastValueFrom(
|
||||
this.pipelineReadService.PipelineV2FindOne(data),
|
||||
)
|
||||
.then((res) => {
|
||||
this.logger.info('Done');
|
||||
return res;
|
||||
})
|
||||
.catch((err) => {
|
||||
this.logger.error(err.message);
|
||||
throw new Error(err);
|
||||
});
|
||||
|
||||
return findOnePipelineResponse;
|
||||
}
|
||||
|
||||
async update(UpdatePipelineRequest: Messages.PipelineV2UpdateRequest) {
|
||||
this.logger.info('PipelinesClientService - Update');
|
||||
|
||||
const updatePipelineResponse = await lastValueFrom(
|
||||
this.pipelineWriteService.PipelineV2Update(UpdatePipelineRequest),
|
||||
)
|
||||
.then((res) => {
|
||||
this.logger.info('Done');
|
||||
return res;
|
||||
})
|
||||
.catch((err) => {
|
||||
this.logger.error(err.message);
|
||||
throw new Error(err);
|
||||
});
|
||||
|
||||
return updatePipelineResponse;
|
||||
}
|
||||
|
||||
async remove(data: Messages.PipelineV2RemoveRequest) {
|
||||
this.logger.info('PipelinesClientService - Remove');
|
||||
|
||||
const removePipelineResponse = await lastValueFrom(
|
||||
this.pipelineWriteService.PipelineV2Remove(data),
|
||||
)
|
||||
.then((res) => {
|
||||
this.logger.info('Done');
|
||||
return res;
|
||||
})
|
||||
.catch((err) => {
|
||||
this.logger.error(err.message);
|
||||
throw new Error(err);
|
||||
});
|
||||
|
||||
return removePipelineResponse;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
import { Metadata } from '@grpc/grpc-js';
|
||||
|
||||
interface Info {
|
||||
customer_id?: string;
|
||||
customer_name?: string;
|
||||
username?: string;
|
||||
user_id?: string;
|
||||
language?: string;
|
||||
details?: string;
|
||||
}
|
||||
|
||||
export const PackTheMetadata = (info: Info): Metadata => {
|
||||
const meta = new Metadata();
|
||||
meta.add('customer_id', info.customer_id);
|
||||
meta.add('customer_name', info.customer_name);
|
||||
meta.add('user_id', info.user_id);
|
||||
meta.add('username', info.username);
|
||||
meta.add('details', info.details);
|
||||
meta.add('language', info.language);
|
||||
|
||||
return meta;
|
||||
};
|
||||
+1
-1
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user