mirror of
https://github.com/n8n-io/n8n.git
synced 2024-12-24 20:24:05 -08:00
fix(Pipedrive Node): Improve type-safety in custom-property handling (#9319)
This commit is contained in:
parent
d0d52def8f
commit
c8895c540e
|
@ -236,14 +236,14 @@ export function pipedriveResolveCustomProperties(
|
||||||
const json = item.json as IDataObject;
|
const json = item.json as IDataObject;
|
||||||
|
|
||||||
// Iterate over all keys and replace the custom ones
|
// 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) {
|
if (customProperties[key] !== undefined) {
|
||||||
// Is a custom property
|
// Is a custom property
|
||||||
customPropertyData = customProperties[key];
|
customPropertyData = customProperties[key];
|
||||||
|
|
||||||
// value is not set, so nothing to resolve
|
// value is not set, so nothing to resolve
|
||||||
if (json[key] === null) {
|
if (value === null) {
|
||||||
json[customPropertyData.name] = json[key];
|
json[customPropertyData.name] = value;
|
||||||
delete json[key];
|
delete json[key];
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
@ -267,7 +267,7 @@ export function pipedriveResolveCustomProperties(
|
||||||
'timerange',
|
'timerange',
|
||||||
].includes(customPropertyData.field_type)
|
].includes(customPropertyData.field_type)
|
||||||
) {
|
) {
|
||||||
json[customPropertyData.name] = json[key];
|
json[customPropertyData.name] = value;
|
||||||
delete json[key];
|
delete json[key];
|
||||||
// type options
|
// type options
|
||||||
} else if (
|
} else if (
|
||||||
|
@ -275,15 +275,19 @@ export function pipedriveResolveCustomProperties(
|
||||||
customPropertyData.options
|
customPropertyData.options
|
||||||
) {
|
) {
|
||||||
const propertyOption = customPropertyData.options.find(
|
const propertyOption = customPropertyData.options.find(
|
||||||
(option) => option.id.toString() === json[key]!.toString(),
|
(option) => option.id.toString() === value?.toString(),
|
||||||
);
|
);
|
||||||
if (propertyOption !== undefined) {
|
if (propertyOption !== undefined) {
|
||||||
json[customPropertyData.name] = propertyOption.label;
|
json[customPropertyData.name] = propertyOption.label;
|
||||||
delete json[key];
|
delete json[key];
|
||||||
}
|
}
|
||||||
// type multioptions
|
// type multioptions
|
||||||
} else if (['set'].includes(customPropertyData.field_type) && customPropertyData.options) {
|
} else if (
|
||||||
const selectedIds = (json[key] as string).split(',');
|
['set'].includes(customPropertyData.field_type) &&
|
||||||
|
customPropertyData.options &&
|
||||||
|
typeof value === 'string'
|
||||||
|
) {
|
||||||
|
const selectedIds = value.split(',');
|
||||||
const selectedLabels = customPropertyData.options
|
const selectedLabels = customPropertyData.options
|
||||||
.filter((option) => selectedIds.includes(option.id.toString()))
|
.filter((option) => selectedIds.includes(option.id.toString()))
|
||||||
.map((option) => option.label);
|
.map((option) => option.label);
|
||||||
|
|
Loading…
Reference in a new issue