mirror of
https://github.com/n8n-io/n8n.git
synced 2025-03-05 20:50:17 -08:00
⚡ Add resolve data to all resources
This commit is contained in:
parent
0735316973
commit
dad3fa355a
|
@ -66,7 +66,6 @@ export async function zohoApiRequest(
|
|||
}
|
||||
|
||||
try {
|
||||
console.log(JSON.stringify(options, null, 2));
|
||||
const responseData = await this.helpers.requestOAuth2?.call(this, 'zohoOAuth2Api', options);
|
||||
|
||||
if (responseData === undefined) return [];
|
||||
|
@ -377,7 +376,7 @@ export async function getFields(
|
|||
return sortBy(options, o => o.name);
|
||||
}
|
||||
|
||||
function getModuleName(resource: string) {
|
||||
export function getModuleName(resource: string) {
|
||||
const map: { [key: string]: string } = {
|
||||
account: 'Accounts',
|
||||
contact: 'Contacts',
|
||||
|
|
|
@ -25,6 +25,7 @@ import {
|
|||
adjustSalesOrderPayload,
|
||||
adjustVendorPayload,
|
||||
getFields,
|
||||
getModuleName,
|
||||
getPicklistOptions,
|
||||
handleListing,
|
||||
throwOnEmptyUpdate,
|
||||
|
@ -321,6 +322,7 @@ export class ZohoCrm implements INodeType {
|
|||
|
||||
const resource = this.getNodeParameter('resource', 0) as CamelCaseResource;
|
||||
const operation = this.getNodeParameter('operation', 0) as string;
|
||||
const resolveData = this.getNodeParameter('resolveData', 0, false) as boolean;
|
||||
|
||||
let responseData;
|
||||
|
||||
|
@ -1444,6 +1446,11 @@ export class ZohoCrm implements INodeType {
|
|||
throw error;
|
||||
}
|
||||
|
||||
if (resolveData) {
|
||||
responseData = await zohoApiRequest.call(this, 'GET', `/${getModuleName(resource)}/${responseData[0].details.id}`);
|
||||
responseData = responseData.data;
|
||||
}
|
||||
|
||||
Array.isArray(responseData)
|
||||
? returnData.push(...responseData)
|
||||
: returnData.push(responseData);
|
||||
|
|
|
@ -7,6 +7,7 @@ import {
|
|||
currencies,
|
||||
makeCustomFieldsFixedCollection,
|
||||
makeGetAllFields,
|
||||
makeResolve,
|
||||
shippingAddress,
|
||||
} from './SharedFields';
|
||||
|
||||
|
@ -75,7 +76,7 @@ export const accountFields = [
|
|||
},
|
||||
},
|
||||
},
|
||||
|
||||
|
||||
// ----------------------------------------
|
||||
// account: upsert
|
||||
// ----------------------------------------
|
||||
|
@ -98,6 +99,8 @@ export const accountFields = [
|
|||
},
|
||||
},
|
||||
|
||||
makeResolve('account', ['create', 'update', 'upsert']),
|
||||
|
||||
// ----------------------------------------
|
||||
// account: create + upsert
|
||||
// ----------------------------------------
|
||||
|
|
|
@ -7,6 +7,7 @@ import {
|
|||
mailingAddress,
|
||||
makeCustomFieldsFixedCollection,
|
||||
makeGetAllFields,
|
||||
makeResolve,
|
||||
otherAddress,
|
||||
} from './SharedFields';
|
||||
|
||||
|
@ -75,6 +76,7 @@ export const contactFields = [
|
|||
},
|
||||
},
|
||||
},
|
||||
makeResolve('contact', ['create']),
|
||||
{
|
||||
displayName: 'Additional Fields',
|
||||
name: 'additionalFields',
|
||||
|
@ -230,6 +232,7 @@ export const contactFields = [
|
|||
},
|
||||
},
|
||||
},
|
||||
makeResolve('contact', ['upsert']),
|
||||
{
|
||||
displayName: 'Additional Fields',
|
||||
name: 'additionalFields',
|
||||
|
@ -436,6 +439,7 @@ export const contactFields = [
|
|||
},
|
||||
},
|
||||
},
|
||||
makeResolve('contact', ['update']),
|
||||
{
|
||||
displayName: 'Update Fields',
|
||||
name: 'updateFields',
|
||||
|
|
|
@ -6,6 +6,7 @@ import {
|
|||
currencies,
|
||||
makeCustomFieldsFixedCollection,
|
||||
makeGetAllFields,
|
||||
makeResolve,
|
||||
} from './SharedFields';
|
||||
|
||||
export const dealOperations = [
|
||||
|
@ -95,7 +96,6 @@ export const dealFields = [
|
|||
},
|
||||
},
|
||||
},
|
||||
|
||||
// ----------------------------------------
|
||||
// deal: create + upsert
|
||||
// ----------------------------------------
|
||||
|
@ -120,6 +120,7 @@ export const dealFields = [
|
|||
},
|
||||
},
|
||||
},
|
||||
makeResolve('deal', ['create', 'upsert']),
|
||||
{
|
||||
displayName: 'Additional Fields',
|
||||
name: 'additionalFields',
|
||||
|
@ -278,6 +279,7 @@ export const dealFields = [
|
|||
},
|
||||
},
|
||||
},
|
||||
makeResolve('deal', ['update']),
|
||||
{
|
||||
displayName: 'Update Fields',
|
||||
name: 'updateFields',
|
||||
|
|
|
@ -7,6 +7,7 @@ import {
|
|||
currencies,
|
||||
makeCustomFieldsFixedCollection,
|
||||
makeGetAllFields,
|
||||
makeResolve,
|
||||
productDetailsOptions,
|
||||
shippingAddress,
|
||||
} from './SharedFields';
|
||||
|
@ -126,6 +127,7 @@ export const invoiceFields = [
|
|||
},
|
||||
},
|
||||
},
|
||||
makeResolve('invoice', ['create', 'upsert']),
|
||||
{
|
||||
displayName: 'Additional Fields',
|
||||
name: 'additionalFields',
|
||||
|
@ -317,6 +319,7 @@ export const invoiceFields = [
|
|||
},
|
||||
},
|
||||
},
|
||||
makeResolve('invoice', ['update']),
|
||||
{
|
||||
displayName: 'Update Fields',
|
||||
name: 'updateFields',
|
||||
|
|
|
@ -7,6 +7,7 @@ import {
|
|||
currencies,
|
||||
makeCustomFieldsFixedCollection,
|
||||
makeGetAllFields,
|
||||
makeResolve,
|
||||
} from './SharedFields';
|
||||
|
||||
export const leadOperations = [
|
||||
|
@ -92,6 +93,7 @@ export const leadFields = [
|
|||
},
|
||||
},
|
||||
},
|
||||
makeResolve('lead', ['create']),
|
||||
{
|
||||
displayName: 'Additional Fields',
|
||||
name: 'additionalFields',
|
||||
|
@ -286,6 +288,7 @@ export const leadFields = [
|
|||
},
|
||||
},
|
||||
},
|
||||
makeResolve('lead', ['upsert']),
|
||||
{
|
||||
displayName: 'Additional Fields',
|
||||
name: 'additionalFields',
|
||||
|
@ -513,6 +516,7 @@ export const leadFields = [
|
|||
},
|
||||
},
|
||||
},
|
||||
makeResolve('lead', ['update']),
|
||||
{
|
||||
displayName: 'Update Fields',
|
||||
name: 'updateFields',
|
||||
|
|
|
@ -5,6 +5,7 @@ import {
|
|||
import {
|
||||
makeCustomFieldsFixedCollection,
|
||||
makeGetAllFields,
|
||||
makeResolve,
|
||||
} from './SharedFields';
|
||||
|
||||
export const productOperations = [
|
||||
|
@ -98,6 +99,8 @@ export const productFields = [
|
|||
// ----------------------------------------
|
||||
// product: create + upsert
|
||||
// ----------------------------------------
|
||||
makeResolve('product', ['create', 'upsert']),
|
||||
|
||||
{
|
||||
displayName: 'Additional Fields',
|
||||
name: 'additionalFields',
|
||||
|
@ -257,6 +260,7 @@ export const productFields = [
|
|||
},
|
||||
},
|
||||
},
|
||||
makeResolve('product', ['update']),
|
||||
{
|
||||
displayName: 'Update Fields',
|
||||
name: 'updateFields',
|
||||
|
|
|
@ -7,6 +7,7 @@ import {
|
|||
currencies,
|
||||
makeCustomFieldsFixedCollection,
|
||||
makeGetAllFields,
|
||||
makeResolve,
|
||||
productDetailsOptions,
|
||||
shippingAddress,
|
||||
} from './SharedFields';
|
||||
|
@ -147,6 +148,8 @@ export const purchaseOrderFields = [
|
|||
},
|
||||
},
|
||||
},
|
||||
makeResolve('purchaseOrder', ['create', 'upsert']),
|
||||
|
||||
{
|
||||
displayName: 'Additional Fields',
|
||||
name: 'additionalFields',
|
||||
|
@ -419,6 +422,7 @@ export const purchaseOrderFields = [
|
|||
},
|
||||
},
|
||||
},
|
||||
makeResolve('purchaseOrder', ['update']),
|
||||
{
|
||||
displayName: 'Update Fields',
|
||||
name: 'updateFields',
|
||||
|
|
|
@ -7,6 +7,7 @@ import {
|
|||
currencies,
|
||||
makeCustomFieldsFixedCollection,
|
||||
makeGetAllFields,
|
||||
makeResolve,
|
||||
productDetailsOptions,
|
||||
shippingAddress,
|
||||
} from './SharedFields';
|
||||
|
@ -126,6 +127,7 @@ export const quoteFields = [
|
|||
},
|
||||
},
|
||||
},
|
||||
makeResolve('quote', ['create', 'upsert']),
|
||||
{
|
||||
displayName: 'Additional Fields',
|
||||
name: 'additionalFields',
|
||||
|
@ -321,6 +323,7 @@ export const quoteFields = [
|
|||
},
|
||||
},
|
||||
},
|
||||
makeResolve('quote', ['update']),
|
||||
{
|
||||
displayName: 'Update Fields',
|
||||
name: 'updateFields',
|
||||
|
|
|
@ -7,6 +7,7 @@ import {
|
|||
currencies,
|
||||
makeCustomFieldsFixedCollection,
|
||||
makeGetAllFields,
|
||||
makeResolve,
|
||||
productDetailsOptions,
|
||||
shippingAddress,
|
||||
} from './SharedFields';
|
||||
|
@ -151,6 +152,7 @@ export const salesOrderFields = [
|
|||
},
|
||||
},
|
||||
},
|
||||
makeResolve('salesOrder', ['create', 'upsert']),
|
||||
{
|
||||
displayName: 'Additional Fields',
|
||||
name: 'additionalFields',
|
||||
|
@ -384,6 +386,7 @@ export const salesOrderFields = [
|
|||
},
|
||||
},
|
||||
},
|
||||
makeResolve('salesOrder', ['update']),
|
||||
{
|
||||
displayName: 'Update Fields',
|
||||
name: 'updateFields',
|
||||
|
|
|
@ -271,43 +271,43 @@ export const productDetailsOptions = [
|
|||
displayName: 'Quantity',
|
||||
name: 'quantity',
|
||||
type: 'number',
|
||||
default: '',
|
||||
default: 1,
|
||||
},
|
||||
{
|
||||
displayName: 'Quantity in Stock',
|
||||
name: 'quantity_in_stock',
|
||||
type: 'number',
|
||||
default: '',
|
||||
default: 0,
|
||||
},
|
||||
{
|
||||
displayName: 'Tax',
|
||||
name: 'Tax',
|
||||
type: 'number',
|
||||
default: '',
|
||||
default: 0,
|
||||
},
|
||||
{
|
||||
displayName: 'Total',
|
||||
name: 'total',
|
||||
type: 'number',
|
||||
default: '',
|
||||
default: 0,
|
||||
},
|
||||
{
|
||||
displayName: 'Total After Discount',
|
||||
name: 'total_after_discount',
|
||||
type: 'number',
|
||||
default: '',
|
||||
default: 0,
|
||||
},
|
||||
{
|
||||
displayName: 'Total (Net)',
|
||||
name: 'net_total',
|
||||
type: 'number',
|
||||
default: '',
|
||||
default: 0,
|
||||
},
|
||||
{
|
||||
displayName: 'Unit Price',
|
||||
name: 'unit_price',
|
||||
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
|
||||
|
||||
export const currencies = [
|
||||
|
|
|
@ -7,6 +7,7 @@ import {
|
|||
currencies,
|
||||
makeCustomFieldsFixedCollection,
|
||||
makeGetAllFields,
|
||||
makeResolve,
|
||||
} from './SharedFields';
|
||||
|
||||
export const vendorOperations = [
|
||||
|
@ -100,6 +101,7 @@ export const vendorFields = [
|
|||
// ----------------------------------------
|
||||
// vendor: create + upsert
|
||||
// ----------------------------------------
|
||||
makeResolve('vendor', ['create', 'upsert']),
|
||||
{
|
||||
displayName: 'Additional Fields',
|
||||
name: 'additionalFields',
|
||||
|
@ -230,6 +232,7 @@ export const vendorFields = [
|
|||
},
|
||||
},
|
||||
},
|
||||
makeResolve('vendor', ['update']),
|
||||
{
|
||||
displayName: 'Update Fields',
|
||||
name: 'updateFields',
|
||||
|
|
Loading…
Reference in a new issue