Files
twenty/packages/twenty-zapier/src/utils/handleQueryParams.ts
martmull a413b29dd4 Fix zapier (#2735)
* Fix zapier tests

* Handle nested fields

* Code review returns
2023-11-27 18:09:21 +01:00

29 lines
1.1 KiB
TypeScript

const handleQueryParams = (inputData: { [x: string]: any }): string => {
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 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;
};
export default handleQueryParams;