Skip to content

Commit

Permalink
fix(Pipedrive Node): Improve type-safety in custom-property handling (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
netroy committed May 8, 2024
1 parent d0d52de commit c8895c5
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions packages/nodes-base/nodes/Pipedrive/GenericFunctions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -267,23 +267,27 @@ export function pipedriveResolveCustomProperties(
'timerange',
].includes(customPropertyData.field_type)
) {
json[customPropertyData.name] = json[key];
json[customPropertyData.name] = value;
delete json[key];
// type options
} else if (
['enum', 'visible_to'].includes(customPropertyData.field_type) &&
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);
Expand Down

0 comments on commit c8895c5

Please sign in to comment.