From 2646e3e4f684721507fce5daab45f3884936f18c Mon Sep 17 00:00:00 2001 From: Gabriel Amorim Date: Fri, 24 Feb 2023 15:58:06 -0300 Subject: [PATCH] FEAT: return google sheets entire link --- docsfera.json | 2 +- src/modules/pipelinesV2/pipelines.service.ts | 38 +++++++++++++------- src/utils/ObjValueFromPath.ts | 5 ++- 3 files changed, 30 insertions(+), 15 deletions(-) diff --git a/docsfera.json b/docsfera.json index dee5148..5f09e71 100644 --- a/docsfera.json +++ b/docsfera.json @@ -4676,7 +4676,7 @@ } }, "info": { - "title": "Maestro - feat/docs-refactor", + "title": "Maestro - feat/google-sheets-link", "description": "This is the Maestro API", "version": "1.0.0", "contact": {} diff --git a/src/modules/pipelinesV2/pipelines.service.ts b/src/modules/pipelinesV2/pipelines.service.ts index dcf740b..2e5fd60 100644 --- a/src/modules/pipelinesV2/pipelines.service.ts +++ b/src/modules/pipelinesV2/pipelines.service.ts @@ -220,7 +220,7 @@ export class PipelinesService implements OnModuleInit { this.logger.info('PipelinesClientService - findOneProperties'); const { pipeline } = await this.findOne({ id }, metadata); - const pipelineProperties = JSON.parse(pipeline.properties); + const properties = JSON.parse(pipeline.properties); const connectorId = `${pipeline.connector_plugin}-${pipeline.connector_version}`; @@ -228,24 +228,36 @@ export class PipelinesService implements OnModuleInit { connectorId, metadata.get('language')[0].toString(), ); - const connector = JSON.parse(res.connector); - const config_controls = connector.config_controls || []; + const connector: { [key: string]: any; config_controls: any[] } = + JSON.parse(res.connector); + const config_controls = (connector.config_controls || []).filter( + (config_control) => { + const path: string = config_control.name; - for (const config_control of config_controls) { - const path: string = config_control.name; - const default_value = getObjValueFromPath({ - object: { properties: pipelineProperties }, - path, - }); - if (default_value != undefined) - config_control.default_value = default_value; - } + let default_value = getObjValueFromPath({ + object: { properties }, + path, + }); + if (default_value != undefined) { + if ( + path === 'properties.spreadsheet_id' && + typeof default_value === 'string' + ) + default_value = 'https://docs.google.com/spreadsheets/d/'.concat( + default_value, + ); + config_control.default_value = default_value; + } + + return true; + }, + ); return { pipeline: { ...pipeline, config_controls, - properties: pipelineProperties, + properties, }, }; } diff --git a/src/utils/ObjValueFromPath.ts b/src/utils/ObjValueFromPath.ts index 43674bd..375d3de 100644 --- a/src/utils/ObjValueFromPath.ts +++ b/src/utils/ObjValueFromPath.ts @@ -1,4 +1,7 @@ -export function getObjValueFromPath(data: { object: T; path: string }): T { +export function getObjValueFromPath(data: { + object: T; + path: string; +}): any { const { object, path } = data; const keys = path.split('.');