Fix zapier (#2735)
* Fix zapier tests * Handle nested fields * Code review returns
This commit is contained in:
@ -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;
|
||||
|
||||
@ -20,9 +20,9 @@ const requestDb = async (z: ZObject, bundle: Bundle, query: string) => {
|
||||
const results = response.json;
|
||||
if (results.errors) {
|
||||
throw new z.errors.Error(
|
||||
'The API Key you supplied is incorrect',
|
||||
'AuthenticationError',
|
||||
results.errors,
|
||||
`query: ${query}, error: ${JSON.stringify(results.errors)}`,
|
||||
'ApiError',
|
||||
response.status
|
||||
);
|
||||
}
|
||||
response.throwForStatus();
|
||||
@ -30,9 +30,9 @@ const requestDb = async (z: ZObject, bundle: Bundle, query: string) => {
|
||||
})
|
||||
.catch((err) => {
|
||||
throw new z.errors.Error(
|
||||
'The API Key you supplied is incorrect',
|
||||
'AuthenticationError',
|
||||
err.message,
|
||||
`query: ${query}, error: ${err.message}`,
|
||||
'Error',
|
||||
err.status
|
||||
);
|
||||
});
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user