From c8895c540e5c8edfb576960a5ba4ec9ac4426d5b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E0=A4=95=E0=A4=BE=E0=A4=B0=E0=A4=A4=E0=A5=8B=E0=A4=AB?= =?UTF-8?q?=E0=A5=8D=E0=A4=AB=E0=A5=87=E0=A4=B2=E0=A4=B8=E0=A5=8D=E0=A4=95?= =?UTF-8?q?=E0=A5=8D=E0=A4=B0=E0=A4=BF=E0=A4=AA=E0=A5=8D=E0=A4=9F=E2=84=A2?= Date: Wed, 8 May 2024 10:36:36 +0200 Subject: [PATCH] fix(Pipedrive Node): Improve type-safety in custom-property handling (#9319) --- .../nodes/Pipedrive/GenericFunctions.ts | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/packages/nodes-base/nodes/Pipedrive/GenericFunctions.ts b/packages/nodes-base/nodes/Pipedrive/GenericFunctions.ts index 0d8719f4cb..b320997a21 100644 --- a/packages/nodes-base/nodes/Pipedrive/GenericFunctions.ts +++ b/packages/nodes-base/nodes/Pipedrive/GenericFunctions.ts @@ -236,14 +236,14 @@ export function pipedriveResolveCustomProperties( const json = item.json as IDataObject; // Iterate over all keys and replace the custom ones - for (const key of Object.keys(json)) { + for (const [key, value] of Object.entries(json)) { if (customProperties[key] !== undefined) { // Is a custom property customPropertyData = customProperties[key]; // value is not set, so nothing to resolve - if (json[key] === null) { - json[customPropertyData.name] = json[key]; + if (value === null) { + json[customPropertyData.name] = value; delete json[key]; continue; } @@ -267,7 +267,7 @@ export function pipedriveResolveCustomProperties( 'timerange', ].includes(customPropertyData.field_type) ) { - json[customPropertyData.name] = json[key]; + json[customPropertyData.name] = value; delete json[key]; // type options } else if ( @@ -275,15 +275,19 @@ export function pipedriveResolveCustomProperties( customPropertyData.options ) { const propertyOption = customPropertyData.options.find( - (option) => option.id.toString() === json[key]!.toString(), + (option) => option.id.toString() === value?.toString(), ); if (propertyOption !== undefined) { json[customPropertyData.name] = propertyOption.label; delete json[key]; } // type multioptions - } else if (['set'].includes(customPropertyData.field_type) && customPropertyData.options) { - const selectedIds = (json[key] as string).split(','); + } else if ( + ['set'].includes(customPropertyData.field_type) && + customPropertyData.options && + typeof value === 'string' + ) { + const selectedIds = value.split(','); const selectedLabels = customPropertyData.options .filter((option) => selectedIds.includes(option.id.toString())) .map((option) => option.label);