Improvements

This commit is contained in:
ricardo 2020-08-18 13:46:38 -04:00
parent 1577322a2a
commit bc71721819
3 changed files with 17 additions and 5 deletions

View file

@ -235,6 +235,7 @@ export const documentFields = [
displayName: 'Properties',
name: 'properties',
type: 'fixedCollection',
placeholder: 'Add Property',
description: 'Properties of request body.',
default: {},
typeOptions: {

View file

@ -20,7 +20,6 @@ import {
erpNextApiRequest,
erpNextApiRequestAllItems
} from './GenericFunctions';
import { filter } from 'rhea';
export class ERPNext implements INodeType {
description: INodeTypeDescription = {
@ -107,12 +106,13 @@ export class ERPNext implements INodeType {
'/api/resource/DocType',
{},
);
for (const type of types) {
const typeName = type.name;
const typeId = type.name;
returnData.push({
name: typeName,
value: typeId
value: encodeURI(typeId)
});
}
return returnData;
@ -132,6 +132,7 @@ export class ERPNext implements INodeType {
{},
);
for (const field of data.fields) {
//field.reqd wheater is required or not
const fieldName = field.label;
const fieldId = field.fieldname;
returnData.push({
@ -226,6 +227,11 @@ export class ERPNext implements INodeType {
if (properties) {
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) {
body[fieldValue.field as string] = fieldValue.value;
}

View file

@ -35,8 +35,6 @@ export async function erpNextApiRequest(this: IExecuteFunctions | IWebhookFuncti
options = Object.assign({}, options, option);
console.log(options);
options.headers!['Authorization'] = `token ${credentials.apiKey}:${credentials.apiSecret}`;
if (Object.keys(body).length === 0) {
@ -45,6 +43,13 @@ export async function erpNextApiRequest(this: IExecuteFunctions | IWebhookFuncti
try {
return await this.helpers.request!(options);
} catch (error) {
if (error.statusCode === 307) {
throw new Error(
`ARPNext error response [${error.statusCode}]: Make sure the subdomain is correct`
);
}
let errorMessages;
if (error.response && error.response.body && 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]);
query!.limit_start += query!.limit_page_lengt - 1;
} while (
responseData.data.length !== 0
responseData.data.length > 0
);
return returnData;