* Add trigger record * Merge triggers * Merge creates * Fix libraries * Fix create merged key * Rename file * Remove list Record Ids * Revert "Rename file" This reverts commit 2e72e05793ced4553eec8d9f890d31beae594c85. * Revert "Revert "Rename file"" This reverts commit e2d93fa02716093df6d4d6029af9cc324c06f06b. * Revert "Remove list Record Ids" This reverts commit 6653fb6ccd4307e3958b70923505034d92cf43bb. * Remove namePlural field * Use name singular for webhooks * Send webhook metadata * Extract resource from zapier webhook * Fix package.json * Fix package.json * Update payload * Fix package.json * Update payload * Update payload * Rename file * Use wildcard in webhook events * Fix nameSingular * Code review returns * Code review returns
35 lines
1.1 KiB
TypeScript
35 lines
1.1 KiB
TypeScript
import { InputData } from '../utils/data.types';
|
|
|
|
const handleQueryParams = (inputData: InputData): string => {
|
|
const formattedInputData: InputData = {};
|
|
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;
|