FIX: do not return config_controls that the pipeline don't have

This commit is contained in:
Gabriel Amorim
2023-02-24 14:31:50 -03:00
parent a9cc951e34
commit 45b82515fc
2 changed files with 35 additions and 14 deletions
+20 -14
View File
@@ -23,7 +23,7 @@ import { ConnectorClientService } from '../connector/client.service';
import { InputsService } from '../inputs/inputs.service';
import { RequestUser } from 'src/decorators/user.decorator';
import { TransformationsService } from '../transformations/transformations.service';
import { getObjValueFromPath } from 'src/utils/ObjValueFromPath';
import { getObjValueFromPath, objHasPath } from 'src/utils/ObjValueFromPath';
import ErrorCodes from 'src/utils/errorCodes';
import ErrorBuilder from 'src/utils/ErrorBuilder';
@@ -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,30 @@ 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;
}
if (!objHasPath({ object: { properties }, path })) return false;
const default_value = getObjValueFromPath({
object: { properties },
path,
});
if (default_value != undefined)
config_control.default_value = default_value;
return true;
},
);
return {
pipeline: {
...pipeline,
config_controls,
properties: pipelineProperties,
properties: properties,
},
};
}