Fix zapier (#2735)

* Fix zapier tests

* Handle nested fields

* Code review returns
This commit is contained in:
martmull
2023-11-27 18:09:21 +01:00
committed by GitHub
parent e2e871ca32
commit a413b29dd4
10 changed files with 137 additions and 80 deletions

View File

@ -1,9 +1,26 @@
const handleQueryParams = (inputData: { [x: string]: any }): string => {
let result = '';
const formattedInputData: {[x:string]: any} = {};
Object.keys(inputData).forEach((key) => {
if(key.includes('__')) {
const [objectKey, nestedObjectKey] = key.split('__')
if (formattedInputData[objectKey]) {
formattedInputData[objectKey][nestedObjectKey] = inputData[key]
} else {
formattedInputData[objectKey] = {[nestedObjectKey]: inputData[key]}
}
} else {
formattedInputData[key]=inputData[key]
}
})
let result = '';
Object.keys(formattedInputData).forEach((key) => {
let quote = '';
if (typeof inputData[key] === 'string') quote = '"';
result = result.concat(`${key}: ${quote}${inputData[key]}${quote}, `);
if (typeof formattedInputData[key]==='object') {
result=result.concat(`${key}: {${handleQueryParams(formattedInputData[key])}}, `)
} else {
if (typeof formattedInputData[key] === 'string') quote = '"';
result = result.concat(`${key}: ${quote}${formattedInputData[key]}${quote}, `);
}
});
if (result.length) result = result.slice(0, -2); // Remove the last ', '
return result;