mirror of
https://github.com/n8n-io/n8n.git
synced 2025-03-05 20:50:17 -08:00
⚡ Implement custom fields adjuster
This commit is contained in:
parent
eb869cd622
commit
07dd734e25
|
@ -65,6 +65,7 @@ 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 [];
|
||||||
|
@ -225,6 +226,22 @@ const adjustAccountIdField = adjustIdField('accountId', 'Account_Name');
|
||||||
const adjustContactIdField = adjustIdField('contactId', 'Full_Name');
|
const adjustContactIdField = adjustIdField('contactId', 'Full_Name');
|
||||||
const adjustDealIdField = adjustIdField('dealId', 'Deal_Name');
|
const adjustDealIdField = adjustIdField('dealId', 'Deal_Name');
|
||||||
|
|
||||||
|
const adjustCustomFields = (allFields: AllFields) => {
|
||||||
|
const { customFields, ...rest } = allFields;
|
||||||
|
|
||||||
|
if (!customFields?.customFields.length) return allFields;
|
||||||
|
|
||||||
|
const customFieldsObject = customFields.customFields.reduce((acc, cur) => {
|
||||||
|
acc[cur.fieldId] = cur.value;
|
||||||
|
return acc;
|
||||||
|
}, {} as { [key: string]: string });
|
||||||
|
|
||||||
|
return {
|
||||||
|
...customFieldsObject,
|
||||||
|
...rest,
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
// ----------------------------------------
|
// ----------------------------------------
|
||||||
// payload adjusters
|
// payload adjusters
|
||||||
// ----------------------------------------
|
// ----------------------------------------
|
||||||
|
@ -232,15 +249,20 @@ const adjustDealIdField = adjustIdField('dealId', 'Deal_Name');
|
||||||
export const adjustAccountPayload = flow(
|
export const adjustAccountPayload = flow(
|
||||||
adjustBillingAddressFields,
|
adjustBillingAddressFields,
|
||||||
adjustShippingAddressFields,
|
adjustShippingAddressFields,
|
||||||
|
adjustCustomFields,
|
||||||
);
|
);
|
||||||
|
|
||||||
export const adjustContactPayload = flow(
|
export const adjustContactPayload = flow(
|
||||||
adjustMailingAddressFields,
|
adjustMailingAddressFields,
|
||||||
adjustOtherAddressFields,
|
adjustOtherAddressFields,
|
||||||
adjustDateOfBirthField,
|
adjustDateOfBirthField,
|
||||||
|
adjustCustomFields,
|
||||||
);
|
);
|
||||||
|
|
||||||
export const adjustDealPayload = adjustClosingDateField;
|
export const adjustDealPayload = flow(
|
||||||
|
adjustClosingDateField,
|
||||||
|
adjustCustomFields,
|
||||||
|
);
|
||||||
|
|
||||||
export const adjustInvoicePayload = flow(
|
export const adjustInvoicePayload = flow(
|
||||||
adjustBillingAddressFields,
|
adjustBillingAddressFields,
|
||||||
|
@ -248,21 +270,27 @@ export const adjustInvoicePayload = flow(
|
||||||
adjustInvoiceDateField,
|
adjustInvoiceDateField,
|
||||||
adjustDueDateField,
|
adjustDueDateField,
|
||||||
adjustAccountIdField,
|
adjustAccountIdField,
|
||||||
|
adjustCustomFields,
|
||||||
);
|
);
|
||||||
|
|
||||||
export const adjustLeadPayload = adjustAddressFields;
|
export const adjustLeadPayload = flow(
|
||||||
|
adjustAddressFields,
|
||||||
|
adjustCustomFields,
|
||||||
|
);
|
||||||
|
|
||||||
export const adjustPurchaseOrderPayload = flow(
|
export const adjustPurchaseOrderPayload = flow(
|
||||||
adjustBillingAddressFields,
|
adjustBillingAddressFields,
|
||||||
adjustShippingAddressFields,
|
adjustShippingAddressFields,
|
||||||
adjustDueDateField,
|
adjustDueDateField,
|
||||||
adjustPurchaseOrderDateField,
|
adjustPurchaseOrderDateField,
|
||||||
|
adjustCustomFields,
|
||||||
);
|
);
|
||||||
|
|
||||||
export const adjustQuotePayload = flow(
|
export const adjustQuotePayload = flow(
|
||||||
adjustBillingAddressFields,
|
adjustBillingAddressFields,
|
||||||
adjustShippingAddressFields,
|
adjustShippingAddressFields,
|
||||||
adjustValidTillField,
|
adjustValidTillField,
|
||||||
|
adjustCustomFields,
|
||||||
);
|
);
|
||||||
|
|
||||||
export const adjustSalesOrderPayload = flow(
|
export const adjustSalesOrderPayload = flow(
|
||||||
|
@ -272,9 +300,13 @@ export const adjustSalesOrderPayload = flow(
|
||||||
adjustAccountIdField,
|
adjustAccountIdField,
|
||||||
adjustContactIdField,
|
adjustContactIdField,
|
||||||
adjustDealIdField,
|
adjustDealIdField,
|
||||||
|
adjustCustomFields,
|
||||||
);
|
);
|
||||||
|
|
||||||
export const adjustVendorPayload = adjustAddressFields;
|
export const adjustVendorPayload = flow(
|
||||||
|
adjustAddressFields,
|
||||||
|
adjustCustomFields,
|
||||||
|
);
|
||||||
|
|
||||||
// ----------------------------------------
|
// ----------------------------------------
|
||||||
// helpers
|
// helpers
|
||||||
|
|
1
packages/nodes-base/nodes/Zoho/types.d.ts
vendored
1
packages/nodes-base/nodes/Zoho/types.d.ts
vendored
|
@ -45,6 +45,7 @@ export type AllFields =
|
||||||
{ [Location in LocationType]?: { address_fields: { [key: string]: string } } } &
|
{ [Location in LocationType]?: { address_fields: { [key: string]: string } } } &
|
||||||
{ Account?: { subfields: { id: string; name: string; } } } &
|
{ Account?: { subfields: { id: string; name: string; } } } &
|
||||||
{ [key in 'accountId' | 'contactId' | 'dealId']?: string } &
|
{ [key in 'accountId' | 'contactId' | 'dealId']?: string } &
|
||||||
|
{ customFields?: { customFields: Array<{ fieldId: string; value: string; }> } } &
|
||||||
IDataObject;
|
IDataObject;
|
||||||
|
|
||||||
export type ProductDetails = Array<{ id: string, quantity: number }>;
|
export type ProductDetails = Array<{ id: string, quantity: number }>;
|
||||||
|
|
Loading…
Reference in a new issue