From 54d10cb873bb5d56e7f147aed91cc760ad7ff97d Mon Sep 17 00:00:00 2001 From: Gabriel Rosa Date: Thu, 17 Nov 2022 09:25:05 -0300 Subject: [PATCH] FIX: try to delete pipeline even if it does not exists in opensearch --- docsfera.json | 2 +- src/modules/pipelinesV2/pipelines.service.ts | 65 +++++++++++--------- 2 files changed, 38 insertions(+), 29 deletions(-) diff --git a/docsfera.json b/docsfera.json index 2042ccd..515464f 100644 --- a/docsfera.json +++ b/docsfera.json @@ -3300,7 +3300,7 @@ "info": { "title": "Maestro - feat/rest-api", "description": "Documentation for Maestro gateway", - "version": "9.11.2022 - 18:24", + "version": "17.11.2022 - 9:23", "contact": {} }, "tags": [], diff --git a/src/modules/pipelinesV2/pipelines.service.ts b/src/modules/pipelinesV2/pipelines.service.ts index d3c1a8e..150017d 100644 --- a/src/modules/pipelinesV2/pipelines.service.ts +++ b/src/modules/pipelinesV2/pipelines.service.ts @@ -17,8 +17,9 @@ import { ConnectorClientService } from '../connector/client.service'; import { InputsService } from '../inputs/inputs.service'; import { RequestUser } from 'src/authentication/user.decorator'; import { TransformationsService } from '../transformations/transformations.service'; -import ErrorBuilder from 'src/utils/ErrorBuilder'; import { getObjValueFromPath } from 'src/utils/ObjValueFromPath'; +import ErrorCodes from 'src/utils/errorCodes'; +import ErrorBuilder from 'src/utils/ErrorBuilder'; export class PipelinesService implements OnModuleInit { logger: DadosferaLogger; @@ -154,45 +155,53 @@ export class PipelinesService implements OnModuleInit { customer_id: user.customer_id, customer: user.customer_name, }; + let existsInProduct = true; const { pipeline } = await lastValueFrom( this.pipelineReadService.PipelineV2FindOne({ id }, metadata), - ); + ).catch((e) => { + if (e.details === ErrorCodes.PIPELINE.NOT_FOUND) existsInProduct = false; + else throw new ErrorBuilder(e.details); + + return { pipeline: undefined }; + }); await lastValueFrom( this.pipelineWriteService.PipelineV2Remove({ id }, metadata), ); - //{pipeline:{tables: {tables: [], input_id: ''}}} - const input = pipeline.config.tables - ? JSON.parse(pipeline.config.tables) - : null; - if (input) - await this.inputsService - .remove({ - id: input.input_id, - info, - }) - .catch((error) => - this.logger.error('Could not delete input', { - data: { input, error }, - }), - ); - - const transformations: { id: string }[] = pipeline.transformations - ? JSON.parse(pipeline.transformations) - : null; - if (transformations && transformations.length) - for (const transformation of transformations) { - await this.transformationsService + if (existsInProduct) { + //{pipeline:{tables: {tables: [], input_id: ''}}} + const input = pipeline.config.tables + ? JSON.parse(pipeline.config.tables) + : null; + if (input) + await this.inputsService .remove({ - id: transformation.id, + id: input.input_id, info, }) .catch((error) => - this.logger.error('Could not delete transformation', { - data: { transformation, error }, + this.logger.error('Could not delete input', { + data: { input, error }, }), ); - } + + const transformations: { id: string }[] = pipeline.transformations + ? JSON.parse(pipeline.transformations) + : null; + if (transformations && transformations.length) + for (const transformation of transformations) { + await this.transformationsService + .remove({ + id: transformation.id, + info, + }) + .catch((error) => + this.logger.error('Could not delete transformation', { + data: { transformation, error }, + }), + ); + } + } } async findOneProperties(id: string, metadata: Metadata) {