mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-17 10:02:05 +00:00
refactor: Format nodes-base package (A-F) (#3800)
* 🔨 prettier formated nodes - A * 🔨 prettier formated nodes - B * ⚡ prettier formated nodes - C * ⚡ prettier formated nodes - D * ⚡ prettier formated nodes - E-F * 🎨 Adjust nodes-base formatting command (#3805) * Format additional files in nodes A-F (#3811) * ⚡ fixes * 🎨 Add Mindee to ignored dirs Co-authored-by: Iván Ovejero <ivov.src@gmail.com>
This commit is contained in:
@@ -1,18 +1,8 @@
|
||||
import {
|
||||
OptionsWithUri,
|
||||
} from 'request';
|
||||
import { OptionsWithUri } from 'request';
|
||||
|
||||
import {
|
||||
IExecuteFunctions,
|
||||
ILoadOptionsFunctions,
|
||||
} from 'n8n-core';
|
||||
import { IExecuteFunctions, ILoadOptionsFunctions } from 'n8n-core';
|
||||
|
||||
import {
|
||||
IDataObject,
|
||||
IHookFunctions,
|
||||
IWebhookFunctions,
|
||||
NodeApiError,
|
||||
} from 'n8n-workflow';
|
||||
import { IDataObject, IHookFunctions, IWebhookFunctions, NodeApiError } from 'n8n-workflow';
|
||||
|
||||
export async function erpNextApiRequest(
|
||||
this: IExecuteFunctions | IWebhookFunctions | IHookFunctions | ILoadOptionsFunctions,
|
||||
@@ -23,12 +13,12 @@ export async function erpNextApiRequest(
|
||||
uri?: string,
|
||||
option: IDataObject = {},
|
||||
) {
|
||||
const credentials = await this.getCredentials('erpNextApi') as ERPNextApiCredentials;
|
||||
const credentials = (await this.getCredentials('erpNextApi')) as ERPNextApiCredentials;
|
||||
const baseUrl = getBaseUrl(credentials);
|
||||
|
||||
let options: OptionsWithUri = {
|
||||
headers: {
|
||||
'Accept': 'application/json',
|
||||
Accept: 'application/json',
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
method,
|
||||
@@ -49,18 +39,19 @@ export async function erpNextApiRequest(
|
||||
delete options.qs;
|
||||
}
|
||||
try {
|
||||
return await this.helpers.requestWithAuthentication.call(this, 'erpNextApi',options);
|
||||
return await this.helpers.requestWithAuthentication.call(this, 'erpNextApi', options);
|
||||
} catch (error) {
|
||||
if (error.statusCode === 403) {
|
||||
throw new NodeApiError(this.getNode(), { message: 'DocType unavailable.' });
|
||||
}
|
||||
|
||||
if (error.statusCode === 307) {
|
||||
throw new NodeApiError(this.getNode(), { message: 'Please ensure the subdomain is correct.' });
|
||||
throw new NodeApiError(this.getNode(), {
|
||||
message: 'Please ensure the subdomain is correct.',
|
||||
});
|
||||
}
|
||||
|
||||
throw new NodeApiError(this.getNode(), error);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -83,9 +74,7 @@ export async function erpNextApiRequestAllItems(
|
||||
responseData = await erpNextApiRequest.call(this, method, resource, body, query);
|
||||
returnData.push.apply(returnData, responseData[propertyName]);
|
||||
query!.limit_start += query!.limit_page_length - 1;
|
||||
} while (
|
||||
responseData.data && responseData.data.length > 0
|
||||
);
|
||||
} while (responseData.data && responseData.data.length > 0);
|
||||
|
||||
return returnData;
|
||||
}
|
||||
@@ -94,9 +83,7 @@ export async function erpNextApiRequestAllItems(
|
||||
* Return the base API URL based on the user's environment.
|
||||
*/
|
||||
const getBaseUrl = ({ environment, domain, subdomain }: ERPNextApiCredentials) =>
|
||||
environment === 'cloudHosted'
|
||||
? `https://${subdomain}.erpnext.com`
|
||||
: domain;
|
||||
environment === 'cloudHosted' ? `https://${subdomain}.erpnext.com` : domain;
|
||||
|
||||
type ERPNextApiCredentials = {
|
||||
apiKey: string;
|
||||
|
||||
Reference in New Issue
Block a user