Improvements

This commit is contained in:
ricardo 2021-05-28 16:47:53 -04:00
parent 0143bca54c
commit a695ef18b3
3 changed files with 68 additions and 40 deletions

View file

@ -58,20 +58,13 @@ export async function zohoApiRequest(
if (!Object.keys(qs).length) {
delete options.qs;
}
try {
let responseData = await this.helpers.requestOAuth2?.call(this, 'zohoOAuth2Api', options);
const responseData = await this.helpers.requestOAuth2?.call(this, 'zohoOAuth2Api', options);
if (responseData === undefined) return [];
throwOnErrorStatus.call(this, responseData);
const operation = this.getNodeParameter('operation', 0) as string;
if (['create', 'delete', 'update', 'get'].includes(operation)) {
responseData = responseData.data[0];
}
return responseData;
} catch (error) {
throw new NodeApiError(this.getNode(), error);
@ -159,6 +152,7 @@ export const adjustProductDetails = (productDetails: ProductDetails) => {
return {
...omit('product', p),
product: { id: p.id },
quantity: p.quantity || 1,
};
});
};

View file

@ -202,7 +202,7 @@ export class ZohoCrm implements INodeType {
// https://www.zoho.com/crm/developer/docs/api/update-specific-record.html
// https://www.zoho.com/crm/developer/docs/api/delete-specific-record.html
try {
//try {
if (resource === 'account') {
@ -229,6 +229,7 @@ export class ZohoCrm implements INodeType {
}
responseData = await zohoApiRequest.call(this, 'POST', '/accounts', body);
responseData = responseData.data;
} else if (operation === 'delete') {
@ -240,6 +241,7 @@ export class ZohoCrm implements INodeType {
const endpoint = `/accounts/${accountId}`;
responseData = await zohoApiRequest.call(this, 'DELETE', endpoint);
responseData = responseData.data;
} else if (operation === 'get') {
@ -251,6 +253,7 @@ export class ZohoCrm implements INodeType {
const endpoint = `/accounts/${accountId}`;
responseData = await zohoApiRequest.call(this, 'GET', endpoint);
responseData = responseData.data;
} else if (operation === 'getAll') {
@ -279,7 +282,7 @@ export class ZohoCrm implements INodeType {
const endpoint = `/accounts/${accountId}`;
responseData = await zohoApiRequest.call(this, 'PUT', endpoint, body);
responseData = responseData.data;
}
} else if (resource === 'contact') {
@ -307,6 +310,7 @@ export class ZohoCrm implements INodeType {
}
responseData = await zohoApiRequest.call(this, 'POST', '/contacts', body);
responseData = responseData.data;
} else if (operation === 'delete') {
@ -318,6 +322,7 @@ export class ZohoCrm implements INodeType {
const endpoint = `/contacts/${contactId}`;
responseData = await zohoApiRequest.call(this, 'DELETE', endpoint);
responseData = responseData.data;
} else if (operation === 'get') {
@ -329,6 +334,7 @@ export class ZohoCrm implements INodeType {
const endpoint = `/contacts/${contactId}`;
responseData = await zohoApiRequest.call(this, 'GET', endpoint);
responseData = responseData.data;
} else if (operation === 'getAll') {
@ -357,7 +363,7 @@ export class ZohoCrm implements INodeType {
const endpoint = `/contacts/${contactId}`;
responseData = await zohoApiRequest.call(this, 'PUT', endpoint, body);
responseData = responseData.data;
}
} else if (resource === 'deal') {
@ -386,6 +392,7 @@ export class ZohoCrm implements INodeType {
}
responseData = await zohoApiRequest.call(this, 'POST', '/deals', body);
responseData = responseData.data;
} else if (operation === 'delete') {
@ -396,6 +403,7 @@ export class ZohoCrm implements INodeType {
const dealId = this.getNodeParameter('dealId', i);
responseData = await zohoApiRequest.call(this, 'DELETE', `/deals/${dealId}`);
responseData = responseData.data;
} else if (operation === 'get') {
@ -406,6 +414,7 @@ export class ZohoCrm implements INodeType {
const dealId = this.getNodeParameter('dealId', i);
responseData = await zohoApiRequest.call(this, 'GET', `/deals/${dealId}`);
responseData = responseData.data;
} else if (operation === 'getAll') {
@ -433,7 +442,7 @@ export class ZohoCrm implements INodeType {
const dealId = this.getNodeParameter('dealId', i);
responseData = await zohoApiRequest.call(this, 'PUT', `/deals/${dealId}`, body);
responseData = responseData.data;
}
} else if (resource === 'invoice') {
@ -464,6 +473,7 @@ export class ZohoCrm implements INodeType {
}
responseData = await zohoApiRequest.call(this, 'POST', '/invoices', body);
responseData = responseData.data;
} else if (operation === 'delete') {
@ -475,6 +485,7 @@ export class ZohoCrm implements INodeType {
const endpoint = `/invoices/${invoiceId}`;
responseData = await zohoApiRequest.call(this, 'DELETE', endpoint);
responseData = responseData.data;
} else if (operation === 'get') {
@ -486,6 +497,7 @@ export class ZohoCrm implements INodeType {
const endpoint = `/invoices/${invoiceId}`;
responseData = await zohoApiRequest.call(this, 'GET', endpoint);
responseData = responseData.data;
} else if (operation === 'getAll') {
@ -514,6 +526,7 @@ export class ZohoCrm implements INodeType {
const endpoint = `/invoices/${invoiceId}`;
responseData = await zohoApiRequest.call(this, 'PUT', endpoint, body);
responseData = responseData.data;
}
@ -543,6 +556,7 @@ export class ZohoCrm implements INodeType {
}
responseData = await zohoApiRequest.call(this, 'POST', '/leads', body);
responseData = responseData.data;
} else if (operation === 'delete') {
@ -553,6 +567,7 @@ export class ZohoCrm implements INodeType {
const leadId = this.getNodeParameter('leadId', i);
responseData = await zohoApiRequest.call(this, 'DELETE', `/leads/${leadId}`);
responseData = responseData.data;
} else if (operation === 'get') {
@ -590,6 +605,7 @@ export class ZohoCrm implements INodeType {
const leadId = this.getNodeParameter('leadId', i);
responseData = await zohoApiRequest.call(this, 'PUT', `/leads/${leadId}`, body);
responseData = responseData.data;
}
@ -618,6 +634,7 @@ export class ZohoCrm implements INodeType {
}
responseData = await zohoApiRequest.call(this, 'POST', '/products', body);
responseData = responseData.data;
} else if (operation === 'delete') {
@ -629,6 +646,7 @@ export class ZohoCrm implements INodeType {
const endpoint = `/products/${productId}`;
responseData = await zohoApiRequest.call(this, 'DELETE', endpoint);
responseData = responseData.data;
} else if (operation === 'get') {
@ -640,6 +658,7 @@ export class ZohoCrm implements INodeType {
const endpoint = `/products/${productId}`;
responseData = await zohoApiRequest.call(this, 'GET', endpoint);
responseData = responseData.data;
} else if (operation === 'getAll') {
@ -668,6 +687,7 @@ export class ZohoCrm implements INodeType {
const endpoint = `/products/${productId}`;
responseData = await zohoApiRequest.call(this, 'PUT', endpoint, body);
responseData = responseData.data;
}
@ -700,6 +720,7 @@ export class ZohoCrm implements INodeType {
}
responseData = await zohoApiRequest.call(this, 'POST', '/purchase_orders', body);
responseData = responseData.data;
} else if (operation === 'delete') {
@ -711,6 +732,7 @@ export class ZohoCrm implements INodeType {
const endpoint = `/purchase_orders/${purchaseOrderId}`;
responseData = await zohoApiRequest.call(this, 'DELETE', endpoint);
responseData = responseData.data;
} else if (operation === 'get') {
@ -722,6 +744,7 @@ export class ZohoCrm implements INodeType {
const endpoint = `/purchase_orders/${purchaseOrderId}`;
responseData = await zohoApiRequest.call(this, 'GET', endpoint);
responseData = responseData.data;
} else if (operation === 'getAll') {
@ -750,6 +773,7 @@ export class ZohoCrm implements INodeType {
const endpoint = `/purchase_orders/${purchaseOrderId}`;
responseData = await zohoApiRequest.call(this, 'PUT', endpoint, body);
responseData = responseData.data;
}
@ -781,6 +805,7 @@ export class ZohoCrm implements INodeType {
}
responseData = await zohoApiRequest.call(this, 'POST', '/quotes', body);
responseData = responseData.data;
} else if (operation === 'delete') {
@ -791,6 +816,7 @@ export class ZohoCrm implements INodeType {
const quoteId = this.getNodeParameter('quoteId', i);
responseData = await zohoApiRequest.call(this, 'DELETE', `/quotes/${quoteId}`);
responseData = responseData.data;
} else if (operation === 'get') {
@ -801,6 +827,7 @@ export class ZohoCrm implements INodeType {
const quoteId = this.getNodeParameter('quoteId', i);
responseData = await zohoApiRequest.call(this, 'GET', `/quotes/${quoteId}`);
responseData = responseData.data;
} else if (operation === 'getAll') {
@ -828,7 +855,7 @@ export class ZohoCrm implements INodeType {
const quoteId = this.getNodeParameter('quoteId', i);
responseData = await zohoApiRequest.call(this, 'PUT', `/quotes/${quoteId}`, body);
responseData = responseData.data;
}
} else if (resource === 'salesOrder') {
@ -860,6 +887,7 @@ export class ZohoCrm implements INodeType {
}
responseData = await zohoApiRequest.call(this, 'POST', '/sales_orders', body);
responseData = responseData.data;
} else if (operation === 'delete') {
@ -871,6 +899,7 @@ export class ZohoCrm implements INodeType {
const endpoint = `/sales_orders/${salesOrderId}`;
responseData = await zohoApiRequest.call(this, 'DELETE', endpoint);
responseData = responseData.data;
} else if (operation === 'get') {
@ -882,6 +911,7 @@ export class ZohoCrm implements INodeType {
const endpoint = `/sales_orders/${salesOrderId}`;
responseData = await zohoApiRequest.call(this, 'GET', endpoint);
responseData = responseData.data;
} else if (operation === 'getAll') {
@ -910,6 +940,7 @@ export class ZohoCrm implements INodeType {
const endpoint = `/sales_orders/${salesOrderId}`;
responseData = await zohoApiRequest.call(this, 'PUT', endpoint, body);
responseData = responseData.data;
}
@ -938,6 +969,7 @@ export class ZohoCrm implements INodeType {
}
responseData = await zohoApiRequest.call(this, 'POST', '/vendors', body);
responseData = responseData.data;
} else if (operation === 'delete') {
@ -949,6 +981,7 @@ export class ZohoCrm implements INodeType {
const endpoint = `/vendors/${vendorId}`;
responseData = await zohoApiRequest.call(this, 'DELETE', endpoint);
responseData = responseData.data;
} else if (operation === 'get') {
@ -960,6 +993,7 @@ export class ZohoCrm implements INodeType {
const endpoint = `/vendors/${vendorId}`;
responseData = await zohoApiRequest.call(this, 'GET', endpoint);
responseData = responseData.data;
} else if (operation === 'getAll') {
@ -988,24 +1022,24 @@ export class ZohoCrm implements INodeType {
const endpoint = `/vendors/${vendorId}`;
responseData = await zohoApiRequest.call(this, 'PUT', endpoint, body);
responseData = responseData.data;
}
}
} catch (error) {
if (this.continueOnFail()) {
returnData.push({ error: error.message });
continue;
}
// } catch (error) {
// if (this.continueOnFail()) {
// returnData.push({ error: error.message });
// continue;
// }
throw error;
}
// throw error;
// }
Array.isArray(responseData)
? returnData.push(...responseData)
: returnData.push(responseData);
}
return [this.helpers.returnJsonArray(returnData)];

View file

@ -10,31 +10,31 @@ export const billingAddress = {
name: 'address_fields',
values: [
{
displayName: 'Billing City',
displayName: 'City',
name: 'Billing_City',
type: 'string',
default: '',
},
{
displayName: 'Billing Country',
displayName: 'Country',
name: 'Billing_Country',
type: 'string',
default: '',
},
{
displayName: 'Billing State',
displayName: 'State',
name: 'Billing_State',
type: 'string',
default: '',
},
{
displayName: 'Billing Street',
displayName: 'Street',
name: 'Billing_Street',
type: 'string',
default: '',
},
{
displayName: 'Billing Zip Code',
displayName: 'Zip Code',
name: 'Billing_Code',
type: 'string',
default: '',
@ -56,31 +56,31 @@ export const shippingAddress = {
name: 'address_fields',
values: [
{
displayName: 'Shipping City',
displayName: 'City',
name: 'Shipping_City',
type: 'string',
default: '',
},
{
displayName: 'Shipping Country',
displayName: 'Country',
name: 'Shipping_Country',
type: 'string',
default: '',
},
{
displayName: 'Shipping State',
displayName: 'State',
name: 'Shipping_State',
type: 'string',
default: '',
},
{
displayName: 'Shipping Street',
displayName: 'Street',
name: 'Shipping_Street',
type: 'string',
default: '',
},
{
displayName: 'Shipping Zip Code',
displayName: 'Zip Code',
name: 'Shipping_Code',
type: 'string',
default: '',
@ -102,31 +102,31 @@ export const mailingAddress = {
name: 'address_fields',
values: [
{
displayName: 'Mailing City',
displayName: 'City',
name: 'Mailing_City',
type: 'string',
default: '',
},
{
displayName: 'Mailing Country',
displayName: 'Country',
name: 'Mailing_Country',
type: 'string',
default: '',
},
{
displayName: 'Mailing State',
displayName: 'State',
name: 'Mailing_State',
type: 'string',
default: '',
},
{
displayName: 'Mailing Street',
displayName: 'Street',
name: 'Mailing_Street',
type: 'string',
default: '',
},
{
displayName: 'Mailing Zip Code',
displayName: 'Zip Code',
name: 'Mailing_Zip',
type: 'string',
default: '',
@ -148,25 +148,25 @@ export const otherAddress = {
name: 'address_fields',
values: [
{
displayName: 'Other City',
displayName: 'City',
name: 'Other_City',
type: 'string',
default: '',
},
{
displayName: 'Other State',
displayName: 'State',
name: 'Other_State',
type: 'string',
default: '',
},
{
displayName: 'Other Street',
displayName: 'Street',
name: 'Other_Street',
type: 'string',
default: '',
},
{
displayName: 'Other Zip Code',
displayName: 'Zip Code',
name: 'Other_Zip',
type: 'string',
default: '',