mirror of
https://github.com/n8n-io/n8n.git
synced 2024-08-16 16:40:30 +03:00
⚡ Improvements
This commit is contained in:
parent
1577322a2a
commit
bc71721819
@ -235,6 +235,7 @@ export const documentFields = [
|
|||||||
displayName: 'Properties',
|
displayName: 'Properties',
|
||||||
name: 'properties',
|
name: 'properties',
|
||||||
type: 'fixedCollection',
|
type: 'fixedCollection',
|
||||||
|
placeholder: 'Add Property',
|
||||||
description: 'Properties of request body.',
|
description: 'Properties of request body.',
|
||||||
default: {},
|
default: {},
|
||||||
typeOptions: {
|
typeOptions: {
|
||||||
|
@ -20,7 +20,6 @@ import {
|
|||||||
erpNextApiRequest,
|
erpNextApiRequest,
|
||||||
erpNextApiRequestAllItems
|
erpNextApiRequestAllItems
|
||||||
} from './GenericFunctions';
|
} from './GenericFunctions';
|
||||||
import { filter } from 'rhea';
|
|
||||||
|
|
||||||
export class ERPNext implements INodeType {
|
export class ERPNext implements INodeType {
|
||||||
description: INodeTypeDescription = {
|
description: INodeTypeDescription = {
|
||||||
@ -107,12 +106,13 @@ export class ERPNext implements INodeType {
|
|||||||
'/api/resource/DocType',
|
'/api/resource/DocType',
|
||||||
{},
|
{},
|
||||||
);
|
);
|
||||||
|
|
||||||
for (const type of types) {
|
for (const type of types) {
|
||||||
const typeName = type.name;
|
const typeName = type.name;
|
||||||
const typeId = type.name;
|
const typeId = type.name;
|
||||||
returnData.push({
|
returnData.push({
|
||||||
name: typeName,
|
name: typeName,
|
||||||
value: typeId
|
value: encodeURI(typeId)
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
return returnData;
|
return returnData;
|
||||||
@ -132,6 +132,7 @@ export class ERPNext implements INodeType {
|
|||||||
{},
|
{},
|
||||||
);
|
);
|
||||||
for (const field of data.fields) {
|
for (const field of data.fields) {
|
||||||
|
//field.reqd wheater is required or not
|
||||||
const fieldName = field.label;
|
const fieldName = field.label;
|
||||||
const fieldId = field.fieldname;
|
const fieldId = field.fieldname;
|
||||||
returnData.push({
|
returnData.push({
|
||||||
@ -226,6 +227,11 @@ export class ERPNext implements INodeType {
|
|||||||
|
|
||||||
if (properties) {
|
if (properties) {
|
||||||
const fieldsValues = (properties as IDataObject).customProperty as IDataObject[];
|
const fieldsValues = (properties as IDataObject).customProperty as IDataObject[];
|
||||||
|
if (Array.isArray(fieldsValues) && fieldsValues.length === 0) {
|
||||||
|
throw new Error(
|
||||||
|
`At least one property has to be defined`,
|
||||||
|
);
|
||||||
|
}
|
||||||
for (const fieldValue of fieldsValues) {
|
for (const fieldValue of fieldsValues) {
|
||||||
body[fieldValue.field as string] = fieldValue.value;
|
body[fieldValue.field as string] = fieldValue.value;
|
||||||
}
|
}
|
||||||
|
@ -35,8 +35,6 @@ export async function erpNextApiRequest(this: IExecuteFunctions | IWebhookFuncti
|
|||||||
|
|
||||||
options = Object.assign({}, options, option);
|
options = Object.assign({}, options, option);
|
||||||
|
|
||||||
console.log(options);
|
|
||||||
|
|
||||||
options.headers!['Authorization'] = `token ${credentials.apiKey}:${credentials.apiSecret}`;
|
options.headers!['Authorization'] = `token ${credentials.apiKey}:${credentials.apiSecret}`;
|
||||||
|
|
||||||
if (Object.keys(body).length === 0) {
|
if (Object.keys(body).length === 0) {
|
||||||
@ -45,6 +43,13 @@ export async function erpNextApiRequest(this: IExecuteFunctions | IWebhookFuncti
|
|||||||
try {
|
try {
|
||||||
return await this.helpers.request!(options);
|
return await this.helpers.request!(options);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
|
||||||
|
if (error.statusCode === 307) {
|
||||||
|
throw new Error(
|
||||||
|
`ARPNext error response [${error.statusCode}]: Make sure the subdomain is correct`
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
let errorMessages;
|
let errorMessages;
|
||||||
if (error.response && error.response.body && error.response.body._server_messages) {
|
if (error.response && error.response.body && error.response.body._server_messages) {
|
||||||
const errors = JSON.parse(error.response.body._server_messages);
|
const errors = JSON.parse(error.response.body._server_messages);
|
||||||
@ -70,7 +75,7 @@ export async function erpNextApiRequestAllItems(this: IHookFunctions | IExecuteF
|
|||||||
returnData.push.apply(returnData, responseData[propertyName]);
|
returnData.push.apply(returnData, responseData[propertyName]);
|
||||||
query!.limit_start += query!.limit_page_lengt - 1;
|
query!.limit_start += query!.limit_page_lengt - 1;
|
||||||
} while (
|
} while (
|
||||||
responseData.data.length !== 0
|
responseData.data.length > 0
|
||||||
);
|
);
|
||||||
|
|
||||||
return returnData;
|
return returnData;
|
||||||
|
Loading…
Reference in New Issue
Block a user