mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-17 18:12:04 +00:00
n8n-3867-progressively-apply-prettier-to-all (#3873)
* 🔨 formatting nodes with prettier
This commit is contained in:
@@ -1,23 +1,10 @@
|
||||
import {
|
||||
OptionsWithUri,
|
||||
} from 'request';
|
||||
import { OptionsWithUri } from 'request';
|
||||
|
||||
import {
|
||||
IExecuteFunctions,
|
||||
IHookFunctions,
|
||||
} from 'n8n-core';
|
||||
import { IExecuteFunctions, IHookFunctions } from 'n8n-core';
|
||||
|
||||
import {
|
||||
IDataObject,
|
||||
ILoadOptionsFunctions,
|
||||
NodeApiError,
|
||||
NodeOperationError,
|
||||
} from 'n8n-workflow';
|
||||
import { IDataObject, ILoadOptionsFunctions, NodeApiError, NodeOperationError } from 'n8n-workflow';
|
||||
|
||||
import {
|
||||
flow,
|
||||
sortBy,
|
||||
} from 'lodash';
|
||||
import { flow, sortBy } from 'lodash';
|
||||
|
||||
import {
|
||||
AllFields,
|
||||
@@ -43,13 +30,13 @@ export async function zohoApiRequest(
|
||||
qs: IDataObject = {},
|
||||
uri?: string,
|
||||
) {
|
||||
const { oauthTokenData } = await this.getCredentials('zohoOAuth2Api') as ZohoOAuth2ApiCredentials;
|
||||
const { oauthTokenData } = (await this.getCredentials(
|
||||
'zohoOAuth2Api',
|
||||
)) as ZohoOAuth2ApiCredentials;
|
||||
|
||||
const options: OptionsWithUri = {
|
||||
body: {
|
||||
data: [
|
||||
body,
|
||||
],
|
||||
data: [body],
|
||||
},
|
||||
method,
|
||||
qs,
|
||||
@@ -99,10 +86,7 @@ export async function zohoApiRequestAllItems(
|
||||
if (Array.isArray(responseData) && !responseData.length) return returnData;
|
||||
returnData.push(...responseData.data);
|
||||
qs.page++;
|
||||
} while (
|
||||
responseData.info.more_records !== undefined &&
|
||||
responseData.info.more_records === true
|
||||
);
|
||||
} while (responseData.info.more_records !== undefined && responseData.info.more_records === true);
|
||||
|
||||
return returnData;
|
||||
}
|
||||
@@ -140,7 +124,7 @@ export function throwOnMissingProducts(
|
||||
this: IExecuteFunctions,
|
||||
resource: CamelCaseResource,
|
||||
productDetails: ProductDetails,
|
||||
) {
|
||||
) {
|
||||
if (!productDetails.length) {
|
||||
throw new NodeOperationError(
|
||||
this.getNode(),
|
||||
@@ -151,7 +135,7 @@ export function throwOnMissingProducts(
|
||||
|
||||
export function throwOnErrorStatus(
|
||||
this: IExecuteFunctions | IHookFunctions | ILoadOptionsFunctions,
|
||||
responseData: { data?: Array<{ status: string, message: string }> },
|
||||
responseData: { data?: Array<{ status: string; message: string }> },
|
||||
) {
|
||||
if (responseData?.data?.[0].status === 'error') {
|
||||
throw new NodeOperationError(this.getNode(), responseData as Error);
|
||||
@@ -166,7 +150,7 @@ export function throwOnErrorStatus(
|
||||
* Place a product ID at a nested position in a product details field.
|
||||
*/
|
||||
export const adjustProductDetails = (productDetails: ProductDetails) => {
|
||||
return productDetails.map(p => {
|
||||
return productDetails.map((p) => {
|
||||
return {
|
||||
...omit('product', p),
|
||||
product: { id: p.id },
|
||||
@@ -187,7 +171,7 @@ export const adjustProductDetails = (productDetails: ProductDetails) => {
|
||||
export const adjustProductDetailsOnUpdate = (allFields: AllFields) => {
|
||||
if (!allFields.Product_Details) return allFields;
|
||||
|
||||
return allFields.Product_Details.map(p => {
|
||||
return allFields.Product_Details.map((p) => {
|
||||
return {
|
||||
...omit('product', p),
|
||||
product: { id: p.id },
|
||||
@@ -219,7 +203,7 @@ const adjustOtherAddressFields = adjustLocationFields('Other_Address');
|
||||
/**
|
||||
* Remove from a date field the timestamp set by the datepicker.
|
||||
*/
|
||||
const adjustDateField = (dateType: DateType) => (allFields: AllFields) => {
|
||||
const adjustDateField = (dateType: DateType) => (allFields: AllFields) => {
|
||||
const dateField = allFields[dateType];
|
||||
|
||||
if (!dateField) return allFields;
|
||||
@@ -282,10 +266,7 @@ export const adjustContactPayload = flow(
|
||||
adjustCustomFields,
|
||||
);
|
||||
|
||||
export const adjustDealPayload = flow(
|
||||
adjustClosingDateField,
|
||||
adjustCustomFields,
|
||||
);
|
||||
export const adjustDealPayload = flow(adjustClosingDateField, adjustCustomFields);
|
||||
|
||||
export const adjustInvoicePayload = flow(
|
||||
adjustBillingAddressFields,
|
||||
@@ -301,10 +282,7 @@ export const adjustInvoicePayloadOnUpdate = flow(
|
||||
adjustProductDetailsOnUpdate,
|
||||
);
|
||||
|
||||
export const adjustLeadPayload = flow(
|
||||
adjustAddressFields,
|
||||
adjustCustomFields,
|
||||
);
|
||||
export const adjustLeadPayload = flow(adjustAddressFields, adjustCustomFields);
|
||||
|
||||
export const adjustPurchaseOrderPayload = flow(
|
||||
adjustBillingAddressFields,
|
||||
@@ -331,10 +309,7 @@ export const adjustSalesOrderPayload = flow(
|
||||
adjustCustomFields,
|
||||
);
|
||||
|
||||
export const adjustVendorPayload = flow(
|
||||
adjustAddressFields,
|
||||
adjustCustomFields,
|
||||
);
|
||||
export const adjustVendorPayload = flow(adjustAddressFields, adjustCustomFields);
|
||||
|
||||
export const adjustProductPayload = adjustCustomFields;
|
||||
|
||||
@@ -345,7 +320,8 @@ export const adjustProductPayload = adjustCustomFields;
|
||||
/**
|
||||
* Create a copy of an object without a specific property.
|
||||
*/
|
||||
const omit = (propertyToOmit: string, { [propertyToOmit]: _, ...remainingObject }) => remainingObject;
|
||||
const omit = (propertyToOmit: string, { [propertyToOmit]: _, ...remainingObject }) =>
|
||||
remainingObject;
|
||||
|
||||
/**
|
||||
* Convert items in a Zoho CRM API response into n8n load options.
|
||||
@@ -363,15 +339,24 @@ export async function getFields(
|
||||
) {
|
||||
const qs = { module: getModuleName(resource) };
|
||||
|
||||
let { fields } = await zohoApiRequest.call(this, 'GET', '/settings/fields', {}, qs) as LoadedFields;
|
||||
let { fields } = (await zohoApiRequest.call(
|
||||
this,
|
||||
'GET',
|
||||
'/settings/fields',
|
||||
{},
|
||||
qs,
|
||||
)) as LoadedFields;
|
||||
|
||||
if (onlyCustom) {
|
||||
fields = fields.filter(({ custom_field }) => custom_field);
|
||||
}
|
||||
|
||||
const options = fields.map(({ field_label, api_name }) => ({ name: field_label, value: api_name }));
|
||||
const options = fields.map(({ field_label, api_name }) => ({
|
||||
name: field_label,
|
||||
value: api_name,
|
||||
}));
|
||||
|
||||
return sortBy(options, o => o.name);
|
||||
return sortBy(options, (o) => o.name);
|
||||
}
|
||||
|
||||
export function getModuleName(resource: string) {
|
||||
@@ -397,21 +382,26 @@ export async function getPicklistOptions(
|
||||
targetField: string,
|
||||
) {
|
||||
const qs = { module: getModuleName(resource) };
|
||||
const responseData = await zohoApiRequest.call(this, 'GET', '/settings/layouts', {}, qs) as LoadedLayouts;
|
||||
const responseData = (await zohoApiRequest.call(
|
||||
this,
|
||||
'GET',
|
||||
'/settings/layouts',
|
||||
{},
|
||||
qs,
|
||||
)) as LoadedLayouts;
|
||||
|
||||
const pickListOptions = responseData.layouts[0]
|
||||
.sections.find(section => section.api_name === getSectionApiName(resource))
|
||||
?.fields.find(f => f.api_name === targetField)
|
||||
?.pick_list_values;
|
||||
const pickListOptions = responseData.layouts[0].sections
|
||||
.find((section) => section.api_name === getSectionApiName(resource))
|
||||
?.fields.find((f) => f.api_name === targetField)?.pick_list_values;
|
||||
|
||||
if (!pickListOptions) return [];
|
||||
|
||||
return pickListOptions.map(
|
||||
(option) => ({ name: option.display_value, value: option.actual_value }),
|
||||
);
|
||||
return pickListOptions.map((option) => ({
|
||||
name: option.display_value,
|
||||
value: option.actual_value,
|
||||
}));
|
||||
}
|
||||
|
||||
|
||||
function getSectionApiName(resource: string) {
|
||||
if (resource === 'purchaseOrder') return 'Purchase Order Information';
|
||||
if (resource === 'salesOrder') return 'Sales Order Information';
|
||||
|
||||
Reference in New Issue
Block a user