fix(Zoho CRM Node): Fix issue with Sales Order not updating (#6959)

This commit is contained in:
Jon 2023-09-11 17:15:52 +01:00 committed by GitHub
parent 5c6cccd4fa
commit fd800b674b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 19 additions and 8 deletions

View file

@ -30,7 +30,9 @@ import type {
export function throwOnErrorStatus( export function throwOnErrorStatus(
this: IExecuteFunctions | IHookFunctions | ILoadOptionsFunctions, this: IExecuteFunctions | IHookFunctions | ILoadOptionsFunctions,
responseData: { data?: Array<{ status: string; message: string }> }, responseData: {
data?: Array<{ status: string; message: string }>;
},
) { ) {
if (responseData?.data?.[0].status === 'error') { if (responseData?.data?.[0].status === 'error') {
throw new NodeOperationError(this.getNode(), responseData as Error); throw new NodeOperationError(this.getNode(), responseData as Error);
@ -69,14 +71,18 @@ export async function zohoApiRequest(
try { try {
const responseData = await this.helpers.requestOAuth2?.call(this, 'zohoOAuth2Api', options); const responseData = await this.helpers.requestOAuth2?.call(this, 'zohoOAuth2Api', options);
if (responseData === undefined) return []; if (responseData === undefined) return [];
throwOnErrorStatus.call(this, responseData as IDataObject); throwOnErrorStatus.call(this, responseData as IDataObject);
return responseData; return responseData;
} catch (error) { } catch (error) {
throw new NodeApiError(this.getNode(), error as JsonObject); const args = error.cause?.data
? {
message: error.cause.data.message || 'The Zoho API returned an error.',
description: JSON.stringify(error.cause.data, null, 2),
}
: undefined;
throw new NodeApiError(this.getNode(), error as JsonObject, args);
} }
} }
@ -161,13 +167,18 @@ const omit = (propertyToOmit: string, { [propertyToOmit]: _, ...remainingObject
/** /**
* Place a product ID at a nested position in a product details field. * Place a product ID at a nested position in a product details field.
*/ */
export const adjustProductDetails = (productDetails: ProductDetails) => { export const adjustProductDetails = (productDetails: ProductDetails, operation?: string) => {
return productDetails.map((p) => { return productDetails.map((p) => {
return { const adjustedProduct = {
...omit('product', p),
product: { id: p.id }, product: { id: p.id },
quantity: p.quantity || 1, quantity: p.quantity || 1,
}; };
if (operation === 'upsert') {
return { ...adjustedProduct, ...omit('id', p) };
} else {
return { ...adjustedProduct, ...omit('product', p) };
}
}); });
}; };

View file

@ -1211,7 +1211,7 @@ export class ZohoCrm implements INodeType {
const body: IDataObject = { const body: IDataObject = {
Account_Name: { id: this.getNodeParameter('accountId', i) }, Account_Name: { id: this.getNodeParameter('accountId', i) },
Subject: this.getNodeParameter('subject', i), Subject: this.getNodeParameter('subject', i),
Product_Details: adjustProductDetails(productDetails), Product_Details: adjustProductDetails(productDetails, 'upsert'),
}; };
const additionalFields = this.getNodeParameter('additionalFields', i); const additionalFields = this.getNodeParameter('additionalFields', i);