Add resolve data to all resources

This commit is contained in:
ricardo 2021-06-24 18:48:08 -04:00
parent 0735316973
commit dad3fa355a
13 changed files with 66 additions and 11 deletions

View file

@ -66,7 +66,6 @@ export async function zohoApiRequest(
} }
try { try {
console.log(JSON.stringify(options, null, 2));
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 [];
@ -377,7 +376,7 @@ export async function getFields(
return sortBy(options, o => o.name); return sortBy(options, o => o.name);
} }
function getModuleName(resource: string) { export function getModuleName(resource: string) {
const map: { [key: string]: string } = { const map: { [key: string]: string } = {
account: 'Accounts', account: 'Accounts',
contact: 'Contacts', contact: 'Contacts',

View file

@ -25,6 +25,7 @@ import {
adjustSalesOrderPayload, adjustSalesOrderPayload,
adjustVendorPayload, adjustVendorPayload,
getFields, getFields,
getModuleName,
getPicklistOptions, getPicklistOptions,
handleListing, handleListing,
throwOnEmptyUpdate, throwOnEmptyUpdate,
@ -321,6 +322,7 @@ export class ZohoCrm implements INodeType {
const resource = this.getNodeParameter('resource', 0) as CamelCaseResource; const resource = this.getNodeParameter('resource', 0) as CamelCaseResource;
const operation = this.getNodeParameter('operation', 0) as string; const operation = this.getNodeParameter('operation', 0) as string;
const resolveData = this.getNodeParameter('resolveData', 0, false) as boolean;
let responseData; let responseData;
@ -1444,6 +1446,11 @@ export class ZohoCrm implements INodeType {
throw error; throw error;
} }
if (resolveData) {
responseData = await zohoApiRequest.call(this, 'GET', `/${getModuleName(resource)}/${responseData[0].details.id}`);
responseData = responseData.data;
}
Array.isArray(responseData) Array.isArray(responseData)
? returnData.push(...responseData) ? returnData.push(...responseData)
: returnData.push(responseData); : returnData.push(responseData);

View file

@ -7,6 +7,7 @@ import {
currencies, currencies,
makeCustomFieldsFixedCollection, makeCustomFieldsFixedCollection,
makeGetAllFields, makeGetAllFields,
makeResolve,
shippingAddress, shippingAddress,
} from './SharedFields'; } from './SharedFields';
@ -98,6 +99,8 @@ export const accountFields = [
}, },
}, },
makeResolve('account', ['create', 'update', 'upsert']),
// ---------------------------------------- // ----------------------------------------
// account: create + upsert // account: create + upsert
// ---------------------------------------- // ----------------------------------------

View file

@ -7,6 +7,7 @@ import {
mailingAddress, mailingAddress,
makeCustomFieldsFixedCollection, makeCustomFieldsFixedCollection,
makeGetAllFields, makeGetAllFields,
makeResolve,
otherAddress, otherAddress,
} from './SharedFields'; } from './SharedFields';
@ -75,6 +76,7 @@ export const contactFields = [
}, },
}, },
}, },
makeResolve('contact', ['create']),
{ {
displayName: 'Additional Fields', displayName: 'Additional Fields',
name: 'additionalFields', name: 'additionalFields',
@ -230,6 +232,7 @@ export const contactFields = [
}, },
}, },
}, },
makeResolve('contact', ['upsert']),
{ {
displayName: 'Additional Fields', displayName: 'Additional Fields',
name: 'additionalFields', name: 'additionalFields',
@ -436,6 +439,7 @@ export const contactFields = [
}, },
}, },
}, },
makeResolve('contact', ['update']),
{ {
displayName: 'Update Fields', displayName: 'Update Fields',
name: 'updateFields', name: 'updateFields',

View file

@ -6,6 +6,7 @@ import {
currencies, currencies,
makeCustomFieldsFixedCollection, makeCustomFieldsFixedCollection,
makeGetAllFields, makeGetAllFields,
makeResolve,
} from './SharedFields'; } from './SharedFields';
export const dealOperations = [ export const dealOperations = [
@ -95,7 +96,6 @@ export const dealFields = [
}, },
}, },
}, },
// ---------------------------------------- // ----------------------------------------
// deal: create + upsert // deal: create + upsert
// ---------------------------------------- // ----------------------------------------
@ -120,6 +120,7 @@ export const dealFields = [
}, },
}, },
}, },
makeResolve('deal', ['create', 'upsert']),
{ {
displayName: 'Additional Fields', displayName: 'Additional Fields',
name: 'additionalFields', name: 'additionalFields',
@ -278,6 +279,7 @@ export const dealFields = [
}, },
}, },
}, },
makeResolve('deal', ['update']),
{ {
displayName: 'Update Fields', displayName: 'Update Fields',
name: 'updateFields', name: 'updateFields',

View file

@ -7,6 +7,7 @@ import {
currencies, currencies,
makeCustomFieldsFixedCollection, makeCustomFieldsFixedCollection,
makeGetAllFields, makeGetAllFields,
makeResolve,
productDetailsOptions, productDetailsOptions,
shippingAddress, shippingAddress,
} from './SharedFields'; } from './SharedFields';
@ -126,6 +127,7 @@ export const invoiceFields = [
}, },
}, },
}, },
makeResolve('invoice', ['create', 'upsert']),
{ {
displayName: 'Additional Fields', displayName: 'Additional Fields',
name: 'additionalFields', name: 'additionalFields',
@ -317,6 +319,7 @@ export const invoiceFields = [
}, },
}, },
}, },
makeResolve('invoice', ['update']),
{ {
displayName: 'Update Fields', displayName: 'Update Fields',
name: 'updateFields', name: 'updateFields',

View file

@ -7,6 +7,7 @@ import {
currencies, currencies,
makeCustomFieldsFixedCollection, makeCustomFieldsFixedCollection,
makeGetAllFields, makeGetAllFields,
makeResolve,
} from './SharedFields'; } from './SharedFields';
export const leadOperations = [ export const leadOperations = [
@ -92,6 +93,7 @@ export const leadFields = [
}, },
}, },
}, },
makeResolve('lead', ['create']),
{ {
displayName: 'Additional Fields', displayName: 'Additional Fields',
name: 'additionalFields', name: 'additionalFields',
@ -286,6 +288,7 @@ export const leadFields = [
}, },
}, },
}, },
makeResolve('lead', ['upsert']),
{ {
displayName: 'Additional Fields', displayName: 'Additional Fields',
name: 'additionalFields', name: 'additionalFields',
@ -513,6 +516,7 @@ export const leadFields = [
}, },
}, },
}, },
makeResolve('lead', ['update']),
{ {
displayName: 'Update Fields', displayName: 'Update Fields',
name: 'updateFields', name: 'updateFields',

View file

@ -5,6 +5,7 @@ import {
import { import {
makeCustomFieldsFixedCollection, makeCustomFieldsFixedCollection,
makeGetAllFields, makeGetAllFields,
makeResolve,
} from './SharedFields'; } from './SharedFields';
export const productOperations = [ export const productOperations = [
@ -98,6 +99,8 @@ export const productFields = [
// ---------------------------------------- // ----------------------------------------
// product: create + upsert // product: create + upsert
// ---------------------------------------- // ----------------------------------------
makeResolve('product', ['create', 'upsert']),
{ {
displayName: 'Additional Fields', displayName: 'Additional Fields',
name: 'additionalFields', name: 'additionalFields',
@ -257,6 +260,7 @@ export const productFields = [
}, },
}, },
}, },
makeResolve('product', ['update']),
{ {
displayName: 'Update Fields', displayName: 'Update Fields',
name: 'updateFields', name: 'updateFields',

View file

@ -7,6 +7,7 @@ import {
currencies, currencies,
makeCustomFieldsFixedCollection, makeCustomFieldsFixedCollection,
makeGetAllFields, makeGetAllFields,
makeResolve,
productDetailsOptions, productDetailsOptions,
shippingAddress, shippingAddress,
} from './SharedFields'; } from './SharedFields';
@ -147,6 +148,8 @@ export const purchaseOrderFields = [
}, },
}, },
}, },
makeResolve('purchaseOrder', ['create', 'upsert']),
{ {
displayName: 'Additional Fields', displayName: 'Additional Fields',
name: 'additionalFields', name: 'additionalFields',
@ -419,6 +422,7 @@ export const purchaseOrderFields = [
}, },
}, },
}, },
makeResolve('purchaseOrder', ['update']),
{ {
displayName: 'Update Fields', displayName: 'Update Fields',
name: 'updateFields', name: 'updateFields',

View file

@ -7,6 +7,7 @@ import {
currencies, currencies,
makeCustomFieldsFixedCollection, makeCustomFieldsFixedCollection,
makeGetAllFields, makeGetAllFields,
makeResolve,
productDetailsOptions, productDetailsOptions,
shippingAddress, shippingAddress,
} from './SharedFields'; } from './SharedFields';
@ -126,6 +127,7 @@ export const quoteFields = [
}, },
}, },
}, },
makeResolve('quote', ['create', 'upsert']),
{ {
displayName: 'Additional Fields', displayName: 'Additional Fields',
name: 'additionalFields', name: 'additionalFields',
@ -321,6 +323,7 @@ export const quoteFields = [
}, },
}, },
}, },
makeResolve('quote', ['update']),
{ {
displayName: 'Update Fields', displayName: 'Update Fields',
name: 'updateFields', name: 'updateFields',

View file

@ -7,6 +7,7 @@ import {
currencies, currencies,
makeCustomFieldsFixedCollection, makeCustomFieldsFixedCollection,
makeGetAllFields, makeGetAllFields,
makeResolve,
productDetailsOptions, productDetailsOptions,
shippingAddress, shippingAddress,
} from './SharedFields'; } from './SharedFields';
@ -151,6 +152,7 @@ export const salesOrderFields = [
}, },
}, },
}, },
makeResolve('salesOrder', ['create', 'upsert']),
{ {
displayName: 'Additional Fields', displayName: 'Additional Fields',
name: 'additionalFields', name: 'additionalFields',
@ -384,6 +386,7 @@ export const salesOrderFields = [
}, },
}, },
}, },
makeResolve('salesOrder', ['update']),
{ {
displayName: 'Update Fields', displayName: 'Update Fields',
name: 'updateFields', name: 'updateFields',

View file

@ -271,43 +271,43 @@ export const productDetailsOptions = [
displayName: 'Quantity', displayName: 'Quantity',
name: 'quantity', name: 'quantity',
type: 'number', type: 'number',
default: '', default: 1,
}, },
{ {
displayName: 'Quantity in Stock', displayName: 'Quantity in Stock',
name: 'quantity_in_stock', name: 'quantity_in_stock',
type: 'number', type: 'number',
default: '', default: 0,
}, },
{ {
displayName: 'Tax', displayName: 'Tax',
name: 'Tax', name: 'Tax',
type: 'number', type: 'number',
default: '', default: 0,
}, },
{ {
displayName: 'Total', displayName: 'Total',
name: 'total', name: 'total',
type: 'number', type: 'number',
default: '', default: 0,
}, },
{ {
displayName: 'Total After Discount', displayName: 'Total After Discount',
name: 'total_after_discount', name: 'total_after_discount',
type: 'number', type: 'number',
default: '', default: 0,
}, },
{ {
displayName: 'Total (Net)', displayName: 'Total (Net)',
name: 'net_total', name: 'net_total',
type: 'number', type: 'number',
default: '', default: 0,
}, },
{ {
displayName: 'Unit Price', displayName: 'Unit Price',
name: 'unit_price', name: 'unit_price',
type: 'number', type: 'number',
default: '', default: 0,
}, },
]; ];
@ -484,6 +484,22 @@ export const makeCustomFieldsFixedCollection = (resource: CamelCaseResource) =>
}; };
}; };
export const makeResolve = (resource: string, operations: string[]) => {
return {
displayName: 'Resolve Data',
name: 'resolveData',
type: 'boolean',
displayOptions: {
show: {
resource: [resource],
operation: operations,
},
},
default: false,
description: `By default the response only contain the ID of the ${resource}. If this option gets activated it<br />will resolve the data automatically.`,
};
};
// https://www.zoho.com/subscriptions/help/supported-currencies.html // https://www.zoho.com/subscriptions/help/supported-currencies.html
export const currencies = [ export const currencies = [

View file

@ -7,6 +7,7 @@ import {
currencies, currencies,
makeCustomFieldsFixedCollection, makeCustomFieldsFixedCollection,
makeGetAllFields, makeGetAllFields,
makeResolve,
} from './SharedFields'; } from './SharedFields';
export const vendorOperations = [ export const vendorOperations = [
@ -100,6 +101,7 @@ export const vendorFields = [
// ---------------------------------------- // ----------------------------------------
// vendor: create + upsert // vendor: create + upsert
// ---------------------------------------- // ----------------------------------------
makeResolve('vendor', ['create', 'upsert']),
{ {
displayName: 'Additional Fields', displayName: 'Additional Fields',
name: 'additionalFields', name: 'additionalFields',
@ -230,6 +232,7 @@ export const vendorFields = [
}, },
}, },
}, },
makeResolve('vendor', ['update']),
{ {
displayName: 'Update Fields', displayName: 'Update Fields',
name: 'updateFields', name: 'updateFields',