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:
Michael Kret
2022-08-01 23:47:55 +03:00
committed by GitHub
parent 2c17e6f3ca
commit 0ecbb4a19d
411 changed files with 12906 additions and 20148 deletions

View File

@@ -1,7 +1,5 @@
/* eslint-disable n8n-nodes-base/node-filename-against-convention */
import {
IExecuteFunctions,
} from 'n8n-core';
import { IExecuteFunctions } from 'n8n-core';
import {
IDataObject,
@@ -13,21 +11,11 @@ import {
NodeOperationError,
} from 'n8n-workflow';
import {
documentFields,
documentOperations,
} from './DocumentDescription';
import { documentFields, documentOperations } from './DocumentDescription';
import {
erpNextApiRequest,
erpNextApiRequestAllItems
} from './GenericFunctions';
import { erpNextApiRequest, erpNextApiRequestAllItems } from './GenericFunctions';
import {
DocumentProperties,
processNames,
toSQL,
} from './utils';
import { DocumentProperties, processNames, toSQL } from './utils';
export class ERPNext implements INodeType {
description: INodeTypeDescription = {
@@ -71,7 +59,13 @@ export class ERPNext implements INodeType {
methods = {
loadOptions: {
async getDocTypes(this: ILoadOptionsFunctions): Promise<INodePropertyOptions[]> {
const data = await erpNextApiRequestAllItems.call(this, 'data', 'GET', '/api/resource/DocType', {});
const data = await erpNextApiRequestAllItems.call(
this,
'data',
'GET',
'/api/resource/DocType',
{},
);
const docTypes = data.map(({ name }: { name: string }) => {
return { name, value: encodeURI(name) };
});
@@ -80,11 +74,18 @@ export class ERPNext implements INodeType {
},
async getDocFilters(this: ILoadOptionsFunctions): Promise<INodePropertyOptions[]> {
const docType = this.getCurrentNodeParameter('docType') as string;
const { data } = await erpNextApiRequest.call(this, 'GET', `/api/resource/DocType/${docType}`, {});
const { data } = await erpNextApiRequest.call(
this,
'GET',
`/api/resource/DocType/${docType}`,
{},
);
const docFields = data.fields.map(({ label, fieldname }: { label: string, fieldname: string }) => {
return ({ name: label, value: fieldname });
});
const docFields = data.fields.map(
({ label, fieldname }: { label: string; fieldname: string }) => {
return { name: label, value: fieldname };
},
);
docFields.unshift({ name: '*', value: '*' });
@@ -92,11 +93,18 @@ export class ERPNext implements INodeType {
},
async getDocFields(this: ILoadOptionsFunctions): Promise<INodePropertyOptions[]> {
const docType = this.getCurrentNodeParameter('docType') as string;
const { data } = await erpNextApiRequest.call(this, 'GET', `/api/resource/DocType/${docType}`, {});
const { data } = await erpNextApiRequest.call(
this,
'GET',
`/api/resource/DocType/${docType}`,
{},
);
const docFields = data.fields.map(({ label, fieldname }: { label: string, fieldname: string }) => {
return ({ name: label, value: fieldname });
});
const docFields = data.fields.map(
({ label, fieldname }: { label: string; fieldname: string }) => {
return { name: label, value: fieldname };
},
);
return processNames(docFields);
},
@@ -116,18 +124,15 @@ export class ERPNext implements INodeType {
const operation = this.getNodeParameter('operation', 0) as string;
for (let i = 0; i < items.length; i++) {
// https://app.swaggerhub.com/apis-docs/alyf.de/ERPNext/11#/Resources/post_api_resource_Webhook
// https://frappeframework.com/docs/user/en/guides/integration/rest_api/manipulating_documents
if (resource === 'document') {
// *********************************************************************
// document
// *********************************************************************
if (operation === 'get') {
// ----------------------------------
// document: get
// ----------------------------------
@@ -137,12 +142,15 @@ export class ERPNext implements INodeType {
const docType = this.getNodeParameter('docType', i) as string;
const documentName = this.getNodeParameter('documentName', i) as string;
responseData = await erpNextApiRequest.call(this, 'GET', `/api/resource/${docType}/${documentName}`);
responseData = await erpNextApiRequest.call(
this,
'GET',
`/api/resource/${docType}/${documentName}`,
);
responseData = responseData.data;
}
if (operation === 'getAll') {
// ----------------------------------
// document: getAll
// ----------------------------------
@@ -152,14 +160,11 @@ export class ERPNext implements INodeType {
const docType = this.getNodeParameter('docType', i) as string;
const endpoint = `/api/resource/${docType}`;
const {
fields,
filters,
} = this.getNodeParameter('options', i) as {
fields: string[],
const { fields, filters } = this.getNodeParameter('options', i) as {
fields: string[];
filters: {
customProperty: Array<{ field: string, operator: string, value: string }>,
},
customProperty: Array<{ field: string; operator: string; value: string }>;
};
};
// fields=["test", "example", "hi"]
@@ -173,14 +178,11 @@ export class ERPNext implements INodeType {
// filters=[["Person","first_name","=","Jane"]]
// TODO: filters not working
if (filters) {
qs.filters = JSON.stringify(filters.customProperty.map((filter) => {
return [
docType,
filter.field,
toSQL(filter.operator),
filter.value,
];
}));
qs.filters = JSON.stringify(
filters.customProperty.map((filter) => {
return [docType, filter.field, toSQL(filter.operator), filter.value];
}),
);
}
const returnAll = this.getNodeParameter('returnAll', i) as boolean;
@@ -191,13 +193,17 @@ export class ERPNext implements INodeType {
qs.limit_start = 0;
responseData = await erpNextApiRequest.call(this, 'GET', endpoint, {}, qs);
responseData = responseData.data;
} else {
responseData = await erpNextApiRequestAllItems.call(this, 'data', 'GET', endpoint, {}, qs);
responseData = await erpNextApiRequestAllItems.call(
this,
'data',
'GET',
endpoint,
{},
qs,
);
}
} else if (operation === 'create') {
// ----------------------------------
// document: create
// ----------------------------------
@@ -207,20 +213,27 @@ export class ERPNext implements INodeType {
const properties = this.getNodeParameter('properties', i) as DocumentProperties;
if (!properties.customProperty.length) {
throw new NodeOperationError(this.getNode(), 'Please enter at least one property for the document to create.', { itemIndex: i },);
throw new NodeOperationError(
this.getNode(),
'Please enter at least one property for the document to create.',
{ itemIndex: i },
);
}
properties.customProperty.forEach(property => {
properties.customProperty.forEach((property) => {
body[property.field] = property.value;
});
const docType = this.getNodeParameter('docType', i) as string;
responseData = await erpNextApiRequest.call(this, 'POST', `/api/resource/${docType}`, body);
responseData = await erpNextApiRequest.call(
this,
'POST',
`/api/resource/${docType}`,
body,
);
responseData = responseData.data;
} else if (operation === 'delete') {
// ----------------------------------
// document: delete
// ----------------------------------
@@ -230,10 +243,12 @@ export class ERPNext implements INodeType {
const docType = this.getNodeParameter('docType', i) as string;
const documentName = this.getNodeParameter('documentName', i) as string;
responseData = await erpNextApiRequest.call(this, 'DELETE', `/api/resource/${docType}/${documentName}`);
responseData = await erpNextApiRequest.call(
this,
'DELETE',
`/api/resource/${docType}/${documentName}`,
);
} else if (operation === 'update') {
// ----------------------------------
// document: update
// ----------------------------------
@@ -243,26 +258,33 @@ export class ERPNext implements INodeType {
const properties = this.getNodeParameter('properties', i) as DocumentProperties;
if (!properties.customProperty.length) {
throw new NodeOperationError(this.getNode(), 'Please enter at least one property for the document to update.', { itemIndex: i });
throw new NodeOperationError(
this.getNode(),
'Please enter at least one property for the document to update.',
{ itemIndex: i },
);
}
properties.customProperty.forEach(property => {
properties.customProperty.forEach((property) => {
body[property.field] = property.value;
});
const docType = this.getNodeParameter('docType', i) as string;
const documentName = this.getNodeParameter('documentName', i) as string;
responseData = await erpNextApiRequest.call(this, 'PUT', `/api/resource/${docType}/${documentName}`, body);
responseData = await erpNextApiRequest.call(
this,
'PUT',
`/api/resource/${docType}/${documentName}`,
body,
);
responseData = responseData.data;
}
}
Array.isArray(responseData)
? returnData.push(...responseData)
: returnData.push(responseData);
}
return [this.helpers.returnJsonArray(returnData)];
}