mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-17 10:02:05 +00:00
n8n-3867-progressively-apply-prettier-to-all (#3873)
* 🔨 formatting nodes with prettier
This commit is contained in:
@@ -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,
|
||||
@@ -48,19 +46,11 @@ import {
|
||||
simplifyTransactionReport,
|
||||
} from './GenericFunctions';
|
||||
|
||||
import {
|
||||
capitalCase,
|
||||
} from 'change-case';
|
||||
import { capitalCase } from 'change-case';
|
||||
|
||||
import {
|
||||
isEmpty,
|
||||
} from 'lodash';
|
||||
import { isEmpty } from 'lodash';
|
||||
|
||||
import {
|
||||
DateFieldsUi,
|
||||
QuickBooksOAuth2Credentials,
|
||||
TransactionFields,
|
||||
} from './types';
|
||||
import { DateFieldsUi, QuickBooksOAuth2Credentials, TransactionFields } from './types';
|
||||
|
||||
export class QuickBooks implements INodeType {
|
||||
description: INodeTypeDescription = {
|
||||
@@ -204,13 +194,14 @@ export class QuickBooks implements INodeType {
|
||||
let responseData;
|
||||
const returnData: IDataObject[] = [];
|
||||
|
||||
const { oauthTokenData } = await this.getCredentials('quickBooksOAuth2Api') as QuickBooksOAuth2Credentials;
|
||||
const { oauthTokenData } = (await this.getCredentials(
|
||||
'quickBooksOAuth2Api',
|
||||
)) as QuickBooksOAuth2Credentials;
|
||||
const companyId = oauthTokenData.callbackQueryString.realmId;
|
||||
|
||||
for (let i = 0; i < items.length; i++) {
|
||||
try {
|
||||
if (resource === 'bill') {
|
||||
|
||||
// *********************************************************************
|
||||
// bill
|
||||
// *********************************************************************
|
||||
@@ -218,7 +209,6 @@ export class QuickBooks implements INodeType {
|
||||
// https://developer.intuit.com/app/developer/qbo/docs/api/accounting/most-commonly-used/bill
|
||||
|
||||
if (operation === 'create') {
|
||||
|
||||
// ----------------------------------
|
||||
// bill: create
|
||||
// ----------------------------------
|
||||
@@ -226,18 +216,47 @@ export class QuickBooks implements INodeType {
|
||||
const lines = this.getNodeParameter('Line', i) as IDataObject[];
|
||||
|
||||
if (!lines.length) {
|
||||
throw new NodeOperationError(this.getNode(), `Please enter at least one line for the ${resource}.`, { itemIndex: i });
|
||||
throw new NodeOperationError(
|
||||
this.getNode(),
|
||||
`Please enter at least one line for the ${resource}.`,
|
||||
{ itemIndex: i },
|
||||
);
|
||||
}
|
||||
|
||||
if (lines.some(line => line.DetailType === undefined || line.Amount === undefined || line.Description === undefined)) {
|
||||
throw new NodeOperationError(this.getNode(), 'Please enter detail type, amount and description for every line.', { itemIndex: i });
|
||||
if (
|
||||
lines.some(
|
||||
(line) =>
|
||||
line.DetailType === undefined ||
|
||||
line.Amount === undefined ||
|
||||
line.Description === undefined,
|
||||
)
|
||||
) {
|
||||
throw new NodeOperationError(
|
||||
this.getNode(),
|
||||
'Please enter detail type, amount and description for every line.',
|
||||
{ itemIndex: i },
|
||||
);
|
||||
}
|
||||
|
||||
lines.forEach(line => {
|
||||
if (line.DetailType === 'AccountBasedExpenseLineDetail' && line.accountId === undefined) {
|
||||
throw new NodeOperationError(this.getNode(), 'Please enter an account ID for the associated line.', { itemIndex: i });
|
||||
} else if (line.DetailType === 'ItemBasedExpenseLineDetail' && line.itemId === undefined) {
|
||||
throw new NodeOperationError(this.getNode(), 'Please enter an item ID for the associated line.', { itemIndex: i });
|
||||
lines.forEach((line) => {
|
||||
if (
|
||||
line.DetailType === 'AccountBasedExpenseLineDetail' &&
|
||||
line.accountId === undefined
|
||||
) {
|
||||
throw new NodeOperationError(
|
||||
this.getNode(),
|
||||
'Please enter an account ID for the associated line.',
|
||||
{ itemIndex: i },
|
||||
);
|
||||
} else if (
|
||||
line.DetailType === 'ItemBasedExpenseLineDetail' &&
|
||||
line.itemId === undefined
|
||||
) {
|
||||
throw new NodeOperationError(
|
||||
this.getNode(),
|
||||
'Please enter an item ID for the associated line.',
|
||||
{ itemIndex: i },
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
@@ -256,9 +275,7 @@ export class QuickBooks implements INodeType {
|
||||
const endpoint = `/v3/company/${companyId}/${resource}`;
|
||||
responseData = await quickBooksApiRequest.call(this, 'POST', endpoint, {}, body);
|
||||
responseData = responseData[capitalCase(resource)];
|
||||
|
||||
} else if (operation === 'delete') {
|
||||
|
||||
// ----------------------------------
|
||||
// bill: delete
|
||||
// ----------------------------------
|
||||
@@ -275,9 +292,7 @@ export class QuickBooks implements INodeType {
|
||||
const endpoint = `/v3/company/${companyId}/${resource}`;
|
||||
responseData = await quickBooksApiRequest.call(this, 'POST', endpoint, qs, body);
|
||||
responseData = responseData[capitalCase(resource)];
|
||||
|
||||
} else if (operation === 'get') {
|
||||
|
||||
// ----------------------------------
|
||||
// bill: get
|
||||
// ----------------------------------
|
||||
@@ -286,23 +301,25 @@ export class QuickBooks implements INodeType {
|
||||
const endpoint = `/v3/company/${companyId}/${resource}/${billId}`;
|
||||
responseData = await quickBooksApiRequest.call(this, 'GET', endpoint, {}, {});
|
||||
responseData = responseData[capitalCase(resource)];
|
||||
|
||||
} else if (operation === 'getAll') {
|
||||
|
||||
// ----------------------------------
|
||||
// bill: getAll
|
||||
// ----------------------------------
|
||||
|
||||
const endpoint = `/v3/company/${companyId}/query`;
|
||||
responseData = await handleListing.call(this, i, endpoint, resource);
|
||||
|
||||
} else if (operation === 'update') {
|
||||
|
||||
// ----------------------------------
|
||||
// bill: update
|
||||
// ----------------------------------
|
||||
|
||||
const { ref, syncToken } = await getRefAndSyncToken.call(this, i, companyId, resource, 'VendorRef');
|
||||
const { ref, syncToken } = await getRefAndSyncToken.call(
|
||||
this,
|
||||
i,
|
||||
companyId,
|
||||
resource,
|
||||
'VendorRef',
|
||||
);
|
||||
|
||||
let body = {
|
||||
Id: this.getNodeParameter('billId', i),
|
||||
@@ -317,7 +334,11 @@ export class QuickBooks implements INodeType {
|
||||
const updateFields = this.getNodeParameter('updateFields', i) as IDataObject;
|
||||
|
||||
if (isEmpty(updateFields)) {
|
||||
throw new NodeOperationError(this.getNode(), `Please enter at least one field to update for the ${resource}.`, { itemIndex: i });
|
||||
throw new NodeOperationError(
|
||||
this.getNode(),
|
||||
`Please enter at least one field to update for the ${resource}.`,
|
||||
{ itemIndex: i },
|
||||
);
|
||||
}
|
||||
|
||||
body = populateFields.call(this, body, updateFields, resource);
|
||||
@@ -325,11 +346,8 @@ export class QuickBooks implements INodeType {
|
||||
const endpoint = `/v3/company/${companyId}/${resource}`;
|
||||
responseData = await quickBooksApiRequest.call(this, 'POST', endpoint, {}, body);
|
||||
responseData = responseData[capitalCase(resource)];
|
||||
|
||||
}
|
||||
|
||||
} else if (resource === 'customer') {
|
||||
|
||||
// *********************************************************************
|
||||
// customer
|
||||
// *********************************************************************
|
||||
@@ -337,7 +355,6 @@ export class QuickBooks implements INodeType {
|
||||
// https://developer.intuit.com/app/developer/qbo/docs/api/accounting/most-commonly-used/customer
|
||||
|
||||
if (operation === 'create') {
|
||||
|
||||
// ----------------------------------
|
||||
// customer: create
|
||||
// ----------------------------------
|
||||
@@ -353,9 +370,7 @@ export class QuickBooks implements INodeType {
|
||||
const endpoint = `/v3/company/${companyId}/${resource}`;
|
||||
responseData = await quickBooksApiRequest.call(this, 'POST', endpoint, {}, body);
|
||||
responseData = responseData[capitalCase(resource)];
|
||||
|
||||
} else if (operation === 'get') {
|
||||
|
||||
// ----------------------------------
|
||||
// customer: get
|
||||
// ----------------------------------
|
||||
@@ -364,18 +379,14 @@ export class QuickBooks implements INodeType {
|
||||
const endpoint = `/v3/company/${companyId}/${resource}/${customerId}`;
|
||||
responseData = await quickBooksApiRequest.call(this, 'GET', endpoint, {}, {});
|
||||
responseData = responseData[capitalCase(resource)];
|
||||
|
||||
} else if (operation === 'getAll') {
|
||||
|
||||
// ----------------------------------
|
||||
// customer: getAll
|
||||
// ----------------------------------
|
||||
|
||||
const endpoint = `/v3/company/${companyId}/query`;
|
||||
responseData = await handleListing.call(this, i, endpoint, resource);
|
||||
|
||||
} else if (operation === 'update') {
|
||||
|
||||
// ----------------------------------
|
||||
// customer: update
|
||||
// ----------------------------------
|
||||
@@ -389,7 +400,11 @@ export class QuickBooks implements INodeType {
|
||||
const updateFields = this.getNodeParameter('updateFields', i) as IDataObject;
|
||||
|
||||
if (isEmpty(updateFields)) {
|
||||
throw new NodeOperationError(this.getNode(), `Please enter at least one field to update for the ${resource}.`, { itemIndex: i });
|
||||
throw new NodeOperationError(
|
||||
this.getNode(),
|
||||
`Please enter at least one field to update for the ${resource}.`,
|
||||
{ itemIndex: i },
|
||||
);
|
||||
}
|
||||
|
||||
body = populateFields.call(this, body, updateFields, resource);
|
||||
@@ -397,17 +412,13 @@ export class QuickBooks implements INodeType {
|
||||
const endpoint = `/v3/company/${companyId}/${resource}`;
|
||||
responseData = await quickBooksApiRequest.call(this, 'POST', endpoint, {}, body);
|
||||
responseData = responseData[capitalCase(resource)];
|
||||
|
||||
}
|
||||
|
||||
} else if (resource === 'employee') {
|
||||
|
||||
// *********************************************************************
|
||||
// employee
|
||||
// *********************************************************************
|
||||
|
||||
if (operation === 'create') {
|
||||
|
||||
// ----------------------------------
|
||||
// employee: create
|
||||
// ----------------------------------
|
||||
@@ -424,9 +435,7 @@ export class QuickBooks implements INodeType {
|
||||
const endpoint = `/v3/company/${companyId}/${resource}`;
|
||||
responseData = await quickBooksApiRequest.call(this, 'POST', endpoint, {}, body);
|
||||
responseData = responseData[capitalCase(resource)];
|
||||
|
||||
} else if (operation === 'get') {
|
||||
|
||||
// ----------------------------------
|
||||
// employee: get
|
||||
// ----------------------------------
|
||||
@@ -435,18 +444,14 @@ export class QuickBooks implements INodeType {
|
||||
const endpoint = `/v3/company/${companyId}/${resource}/${employeeId}`;
|
||||
responseData = await quickBooksApiRequest.call(this, 'GET', endpoint, {}, {});
|
||||
responseData = responseData[capitalCase(resource)];
|
||||
|
||||
} else if (operation === 'getAll') {
|
||||
|
||||
// ----------------------------------
|
||||
// employee: getAll
|
||||
// ----------------------------------
|
||||
|
||||
const endpoint = `/v3/company/${companyId}/query`;
|
||||
responseData = await handleListing.call(this, i, endpoint, resource);
|
||||
|
||||
} else if (operation === 'update') {
|
||||
|
||||
// ----------------------------------
|
||||
// employee: update
|
||||
// ----------------------------------
|
||||
@@ -460,7 +465,11 @@ export class QuickBooks implements INodeType {
|
||||
const updateFields = this.getNodeParameter('updateFields', i) as IDataObject;
|
||||
|
||||
if (isEmpty(updateFields)) {
|
||||
throw new NodeOperationError(this.getNode(), `Please enter at least one field to update for the ${resource}.`, { itemIndex: i });
|
||||
throw new NodeOperationError(
|
||||
this.getNode(),
|
||||
`Please enter at least one field to update for the ${resource}.`,
|
||||
{ itemIndex: i },
|
||||
);
|
||||
}
|
||||
|
||||
body = populateFields.call(this, body, updateFields, resource);
|
||||
@@ -468,11 +477,8 @@ export class QuickBooks implements INodeType {
|
||||
const endpoint = `/v3/company/${companyId}/${resource}`;
|
||||
responseData = await quickBooksApiRequest.call(this, 'POST', endpoint, {}, body);
|
||||
responseData = responseData[capitalCase(resource)];
|
||||
|
||||
}
|
||||
|
||||
} else if (resource === 'estimate') {
|
||||
|
||||
// *********************************************************************
|
||||
// estimate
|
||||
// *********************************************************************
|
||||
@@ -480,7 +486,6 @@ export class QuickBooks implements INodeType {
|
||||
// https://developer.intuit.com/app/developer/qbo/docs/api/accounting/most-commonly-used/estimate
|
||||
|
||||
if (operation === 'create') {
|
||||
|
||||
// ----------------------------------
|
||||
// estimate: create
|
||||
// ----------------------------------
|
||||
@@ -488,16 +493,35 @@ export class QuickBooks implements INodeType {
|
||||
const lines = this.getNodeParameter('Line', i) as IDataObject[];
|
||||
|
||||
if (!lines.length) {
|
||||
throw new NodeOperationError(this.getNode(), `Please enter at least one line for the ${resource}.`, { itemIndex: i });
|
||||
throw new NodeOperationError(
|
||||
this.getNode(),
|
||||
`Please enter at least one line for the ${resource}.`,
|
||||
{ itemIndex: i },
|
||||
);
|
||||
}
|
||||
|
||||
if (lines.some(line => line.DetailType === undefined || line.Amount === undefined || line.Description === undefined)) {
|
||||
throw new NodeOperationError(this.getNode(), 'Please enter detail type, amount and description for every line.', { itemIndex: i });
|
||||
if (
|
||||
lines.some(
|
||||
(line) =>
|
||||
line.DetailType === undefined ||
|
||||
line.Amount === undefined ||
|
||||
line.Description === undefined,
|
||||
)
|
||||
) {
|
||||
throw new NodeOperationError(
|
||||
this.getNode(),
|
||||
'Please enter detail type, amount and description for every line.',
|
||||
{ itemIndex: i },
|
||||
);
|
||||
}
|
||||
|
||||
lines.forEach(line => {
|
||||
lines.forEach((line) => {
|
||||
if (line.DetailType === 'SalesItemLineDetail' && line.itemId === undefined) {
|
||||
throw new NodeOperationError(this.getNode(), 'Please enter an item ID for the associated line.', { itemIndex: i });
|
||||
throw new NodeOperationError(
|
||||
this.getNode(),
|
||||
'Please enter an item ID for the associated line.',
|
||||
{ itemIndex: i },
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
@@ -515,9 +539,7 @@ export class QuickBooks implements INodeType {
|
||||
const endpoint = `/v3/company/${companyId}/${resource}`;
|
||||
responseData = await quickBooksApiRequest.call(this, 'POST', endpoint, {}, body);
|
||||
responseData = responseData[capitalCase(resource)];
|
||||
|
||||
} else if (operation === 'delete') {
|
||||
|
||||
// ----------------------------------
|
||||
// estimate: delete
|
||||
// ----------------------------------
|
||||
@@ -534,9 +556,7 @@ export class QuickBooks implements INodeType {
|
||||
const endpoint = `/v3/company/${companyId}/${resource}`;
|
||||
responseData = await quickBooksApiRequest.call(this, 'POST', endpoint, qs, body);
|
||||
responseData = responseData[capitalCase(resource)];
|
||||
|
||||
} else if (operation === 'get') {
|
||||
|
||||
// ----------------------------------
|
||||
// estimate: get
|
||||
// ----------------------------------
|
||||
@@ -545,28 +565,27 @@ export class QuickBooks implements INodeType {
|
||||
const download = this.getNodeParameter('download', i) as boolean;
|
||||
|
||||
if (download) {
|
||||
|
||||
responseData = await handleBinaryData.call(this, items, i, companyId, resource, estimateId);
|
||||
|
||||
responseData = await handleBinaryData.call(
|
||||
this,
|
||||
items,
|
||||
i,
|
||||
companyId,
|
||||
resource,
|
||||
estimateId,
|
||||
);
|
||||
} else {
|
||||
|
||||
const endpoint = `/v3/company/${companyId}/${resource}/${estimateId}`;
|
||||
responseData = await quickBooksApiRequest.call(this, 'GET', endpoint, {}, {});
|
||||
responseData = responseData[capitalCase(resource)];
|
||||
|
||||
}
|
||||
|
||||
} else if (operation === 'getAll') {
|
||||
|
||||
// ----------------------------------
|
||||
// estimate: getAll
|
||||
// ----------------------------------
|
||||
|
||||
const endpoint = `/v3/company/${companyId}/query`;
|
||||
responseData = await handleListing.call(this, i, endpoint, resource);
|
||||
|
||||
} else if (operation === 'send') {
|
||||
|
||||
// ----------------------------------
|
||||
// estimate: send
|
||||
// ----------------------------------
|
||||
@@ -580,14 +599,18 @@ export class QuickBooks implements INodeType {
|
||||
const endpoint = `/v3/company/${companyId}/${resource}/${estimateId}/send`;
|
||||
responseData = await quickBooksApiRequest.call(this, 'POST', endpoint, qs, {});
|
||||
responseData = responseData[capitalCase(resource)];
|
||||
|
||||
} else if (operation === 'update') {
|
||||
|
||||
// ----------------------------------
|
||||
// estimate: update
|
||||
// ----------------------------------
|
||||
|
||||
const { ref, syncToken } = await getRefAndSyncToken.call(this, i, companyId, resource, 'CustomerRef');
|
||||
const { ref, syncToken } = await getRefAndSyncToken.call(
|
||||
this,
|
||||
i,
|
||||
companyId,
|
||||
resource,
|
||||
'CustomerRef',
|
||||
);
|
||||
|
||||
let body = {
|
||||
Id: this.getNodeParameter('estimateId', i),
|
||||
@@ -602,7 +625,11 @@ export class QuickBooks implements INodeType {
|
||||
const updateFields = this.getNodeParameter('updateFields', i) as IDataObject;
|
||||
|
||||
if (isEmpty(updateFields)) {
|
||||
throw new NodeOperationError(this.getNode(), `Please enter at least one field to update for the ${resource}.`, { itemIndex: i });
|
||||
throw new NodeOperationError(
|
||||
this.getNode(),
|
||||
`Please enter at least one field to update for the ${resource}.`,
|
||||
{ itemIndex: i },
|
||||
);
|
||||
}
|
||||
|
||||
body = populateFields.call(this, body, updateFields, resource);
|
||||
@@ -610,11 +637,8 @@ export class QuickBooks implements INodeType {
|
||||
const endpoint = `/v3/company/${companyId}/${resource}`;
|
||||
responseData = await quickBooksApiRequest.call(this, 'POST', endpoint, {}, body);
|
||||
responseData = responseData[capitalCase(resource)];
|
||||
|
||||
}
|
||||
|
||||
} else if (resource === 'invoice') {
|
||||
|
||||
// *********************************************************************
|
||||
// invoice
|
||||
// *********************************************************************
|
||||
@@ -622,7 +646,6 @@ export class QuickBooks implements INodeType {
|
||||
// https://developer.intuit.com/app/developer/qbo/docs/api/accounting/most-commonly-used/invoice
|
||||
|
||||
if (operation === 'create') {
|
||||
|
||||
// ----------------------------------
|
||||
// invoice: create
|
||||
// ----------------------------------
|
||||
@@ -630,16 +653,35 @@ export class QuickBooks implements INodeType {
|
||||
const lines = this.getNodeParameter('Line', i) as IDataObject[];
|
||||
|
||||
if (!lines.length) {
|
||||
throw new NodeOperationError(this.getNode(), `Please enter at least one line for the ${resource}.`, { itemIndex: i });
|
||||
throw new NodeOperationError(
|
||||
this.getNode(),
|
||||
`Please enter at least one line for the ${resource}.`,
|
||||
{ itemIndex: i },
|
||||
);
|
||||
}
|
||||
|
||||
if (lines.some(line => line.DetailType === undefined || line.Amount === undefined || line.Description === undefined)) {
|
||||
throw new NodeOperationError(this.getNode(), 'Please enter detail type, amount and description for every line.', { itemIndex: i });
|
||||
if (
|
||||
lines.some(
|
||||
(line) =>
|
||||
line.DetailType === undefined ||
|
||||
line.Amount === undefined ||
|
||||
line.Description === undefined,
|
||||
)
|
||||
) {
|
||||
throw new NodeOperationError(
|
||||
this.getNode(),
|
||||
'Please enter detail type, amount and description for every line.',
|
||||
{ itemIndex: i },
|
||||
);
|
||||
}
|
||||
|
||||
lines.forEach(line => {
|
||||
lines.forEach((line) => {
|
||||
if (line.DetailType === 'SalesItemLineDetail' && line.itemId === undefined) {
|
||||
throw new NodeOperationError(this.getNode(), 'Please enter an item ID for the associated line.', { itemIndex: i });
|
||||
throw new NodeOperationError(
|
||||
this.getNode(),
|
||||
'Please enter an item ID for the associated line.',
|
||||
{ itemIndex: i },
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
@@ -658,9 +700,7 @@ export class QuickBooks implements INodeType {
|
||||
const endpoint = `/v3/company/${companyId}/${resource}`;
|
||||
responseData = await quickBooksApiRequest.call(this, 'POST', endpoint, {}, body);
|
||||
responseData = responseData[capitalCase(resource)];
|
||||
|
||||
} else if (operation === 'delete') {
|
||||
|
||||
// ----------------------------------
|
||||
// invoice: delete
|
||||
// ----------------------------------
|
||||
@@ -677,9 +717,7 @@ export class QuickBooks implements INodeType {
|
||||
const endpoint = `/v3/company/${companyId}/${resource}`;
|
||||
responseData = await quickBooksApiRequest.call(this, 'POST', endpoint, qs, body);
|
||||
responseData = responseData[capitalCase(resource)];
|
||||
|
||||
} else if (operation === 'get') {
|
||||
|
||||
// ----------------------------------
|
||||
// invoice: get
|
||||
// ----------------------------------
|
||||
@@ -688,28 +726,27 @@ export class QuickBooks implements INodeType {
|
||||
const download = this.getNodeParameter('download', i) as boolean;
|
||||
|
||||
if (download) {
|
||||
|
||||
responseData = await handleBinaryData.call(this, items, i, companyId, resource, invoiceId);
|
||||
|
||||
responseData = await handleBinaryData.call(
|
||||
this,
|
||||
items,
|
||||
i,
|
||||
companyId,
|
||||
resource,
|
||||
invoiceId,
|
||||
);
|
||||
} else {
|
||||
|
||||
const endpoint = `/v3/company/${companyId}/${resource}/${invoiceId}`;
|
||||
responseData = await quickBooksApiRequest.call(this, 'GET', endpoint, {}, {});
|
||||
responseData = responseData[capitalCase(resource)];
|
||||
|
||||
}
|
||||
|
||||
} else if (operation === 'getAll') {
|
||||
|
||||
// ----------------------------------
|
||||
// invoice: getAll
|
||||
// ----------------------------------
|
||||
|
||||
const endpoint = `/v3/company/${companyId}/query`;
|
||||
responseData = await handleListing.call(this, i, endpoint, resource);
|
||||
|
||||
} else if (operation === 'send') {
|
||||
|
||||
// ----------------------------------
|
||||
// invoice: send
|
||||
// ----------------------------------
|
||||
@@ -723,14 +760,18 @@ export class QuickBooks implements INodeType {
|
||||
const endpoint = `/v3/company/${companyId}/${resource}/${invoiceId}/send`;
|
||||
responseData = await quickBooksApiRequest.call(this, 'POST', endpoint, qs, {});
|
||||
responseData = responseData[capitalCase(resource)];
|
||||
|
||||
} else if (operation === 'update') {
|
||||
|
||||
// ----------------------------------
|
||||
// invoice: update
|
||||
// ----------------------------------
|
||||
|
||||
const { ref, syncToken } = await getRefAndSyncToken.call(this, i, companyId, resource, 'CustomerRef');
|
||||
const { ref, syncToken } = await getRefAndSyncToken.call(
|
||||
this,
|
||||
i,
|
||||
companyId,
|
||||
resource,
|
||||
'CustomerRef',
|
||||
);
|
||||
|
||||
let body = {
|
||||
Id: this.getNodeParameter('invoiceId', i),
|
||||
@@ -745,7 +786,11 @@ export class QuickBooks implements INodeType {
|
||||
const updateFields = this.getNodeParameter('updateFields', i) as IDataObject;
|
||||
|
||||
if (isEmpty(updateFields)) {
|
||||
throw new NodeOperationError(this.getNode(), `Please enter at least one field to update for the ${resource}.`, { itemIndex: i });
|
||||
throw new NodeOperationError(
|
||||
this.getNode(),
|
||||
`Please enter at least one field to update for the ${resource}.`,
|
||||
{ itemIndex: i },
|
||||
);
|
||||
}
|
||||
|
||||
body = populateFields.call(this, body, updateFields, resource);
|
||||
@@ -753,9 +798,7 @@ export class QuickBooks implements INodeType {
|
||||
const endpoint = `/v3/company/${companyId}/${resource}`;
|
||||
responseData = await quickBooksApiRequest.call(this, 'POST', endpoint, {}, body);
|
||||
responseData = responseData[capitalCase(resource)];
|
||||
|
||||
} else if (operation === 'void') {
|
||||
|
||||
// ----------------------------------
|
||||
// invoice: void
|
||||
// ----------------------------------
|
||||
@@ -769,11 +812,8 @@ export class QuickBooks implements INodeType {
|
||||
const endpoint = `/v3/company/${companyId}/${resource}`;
|
||||
responseData = await quickBooksApiRequest.call(this, 'POST', endpoint, qs, {});
|
||||
responseData = responseData[capitalCase(resource)];
|
||||
|
||||
}
|
||||
|
||||
} else if (resource === 'item') {
|
||||
|
||||
// *********************************************************************
|
||||
// item
|
||||
// *********************************************************************
|
||||
@@ -781,7 +821,6 @@ export class QuickBooks implements INodeType {
|
||||
// https://developer.intuit.com/app/developer/qbo/docs/api/accounting/most-commonly-used/item
|
||||
|
||||
if (operation === 'get') {
|
||||
|
||||
// ----------------------------------
|
||||
// item: get
|
||||
// ----------------------------------
|
||||
@@ -790,20 +829,15 @@ export class QuickBooks implements INodeType {
|
||||
const endpoint = `/v3/company/${companyId}/${resource}/${item}`;
|
||||
responseData = await quickBooksApiRequest.call(this, 'GET', endpoint, {}, {});
|
||||
responseData = responseData[capitalCase(resource)];
|
||||
|
||||
} else if (operation === 'getAll') {
|
||||
|
||||
// ----------------------------------
|
||||
// item: getAll
|
||||
// ----------------------------------
|
||||
|
||||
const endpoint = `/v3/company/${companyId}/query`;
|
||||
responseData = await handleListing.call(this, i, endpoint, resource);
|
||||
|
||||
}
|
||||
|
||||
} else if (resource === 'payment') {
|
||||
|
||||
// *********************************************************************
|
||||
// payment
|
||||
// *********************************************************************
|
||||
@@ -811,7 +845,6 @@ export class QuickBooks implements INodeType {
|
||||
// https://developer.intuit.com/app/developer/qbo/docs/api/accounting/most-commonly-used/payment
|
||||
|
||||
if (operation === 'create') {
|
||||
|
||||
// ----------------------------------
|
||||
// payment: create
|
||||
// ----------------------------------
|
||||
@@ -830,9 +863,7 @@ export class QuickBooks implements INodeType {
|
||||
const endpoint = `/v3/company/${companyId}/${resource}`;
|
||||
responseData = await quickBooksApiRequest.call(this, 'POST', endpoint, {}, body);
|
||||
responseData = responseData[capitalCase(resource)];
|
||||
|
||||
} else if (operation === 'delete') {
|
||||
|
||||
// ----------------------------------
|
||||
// payment: delete
|
||||
// ----------------------------------
|
||||
@@ -849,9 +880,7 @@ export class QuickBooks implements INodeType {
|
||||
const endpoint = `/v3/company/${companyId}/${resource}`;
|
||||
responseData = await quickBooksApiRequest.call(this, 'POST', endpoint, qs, body);
|
||||
responseData = responseData[capitalCase(resource)];
|
||||
|
||||
} else if (operation === 'get') {
|
||||
|
||||
// ----------------------------------
|
||||
// payment: get
|
||||
// ----------------------------------
|
||||
@@ -860,28 +889,27 @@ export class QuickBooks implements INodeType {
|
||||
const download = this.getNodeParameter('download', i) as boolean;
|
||||
|
||||
if (download) {
|
||||
|
||||
responseData = await handleBinaryData.call(this, items, i, companyId, resource, paymentId);
|
||||
|
||||
responseData = await handleBinaryData.call(
|
||||
this,
|
||||
items,
|
||||
i,
|
||||
companyId,
|
||||
resource,
|
||||
paymentId,
|
||||
);
|
||||
} else {
|
||||
|
||||
const endpoint = `/v3/company/${companyId}/${resource}/${paymentId}`;
|
||||
responseData = await quickBooksApiRequest.call(this, 'GET', endpoint, {}, {});
|
||||
responseData = responseData[capitalCase(resource)];
|
||||
|
||||
}
|
||||
|
||||
} else if (operation === 'getAll') {
|
||||
|
||||
// ----------------------------------
|
||||
// payment: getAll
|
||||
// ----------------------------------
|
||||
|
||||
const endpoint = `/v3/company/${companyId}/query`;
|
||||
responseData = await handleListing.call(this, i, endpoint, resource);
|
||||
|
||||
} else if (operation === 'send') {
|
||||
|
||||
// ----------------------------------
|
||||
// payment: send
|
||||
// ----------------------------------
|
||||
@@ -895,14 +923,18 @@ export class QuickBooks implements INodeType {
|
||||
const endpoint = `/v3/company/${companyId}/${resource}/${paymentId}/send`;
|
||||
responseData = await quickBooksApiRequest.call(this, 'POST', endpoint, qs, {});
|
||||
responseData = responseData[capitalCase(resource)];
|
||||
|
||||
} else if (operation === 'update') {
|
||||
|
||||
// ----------------------------------
|
||||
// payment: update
|
||||
// ----------------------------------
|
||||
|
||||
const { ref, syncToken } = await getRefAndSyncToken.call(this, i, companyId, resource, 'CustomerRef');
|
||||
const { ref, syncToken } = await getRefAndSyncToken.call(
|
||||
this,
|
||||
i,
|
||||
companyId,
|
||||
resource,
|
||||
'CustomerRef',
|
||||
);
|
||||
|
||||
let body = {
|
||||
Id: this.getNodeParameter('paymentId', i),
|
||||
@@ -917,7 +949,11 @@ export class QuickBooks implements INodeType {
|
||||
const updateFields = this.getNodeParameter('updateFields', i) as IDataObject;
|
||||
|
||||
if (isEmpty(updateFields)) {
|
||||
throw new NodeOperationError(this.getNode(), `Please enter at least one field to update for the ${resource}.`, { itemIndex: i });
|
||||
throw new NodeOperationError(
|
||||
this.getNode(),
|
||||
`Please enter at least one field to update for the ${resource}.`,
|
||||
{ itemIndex: i },
|
||||
);
|
||||
}
|
||||
|
||||
body = populateFields.call(this, body, updateFields, resource);
|
||||
@@ -925,9 +961,7 @@ export class QuickBooks implements INodeType {
|
||||
const endpoint = `/v3/company/${companyId}/${resource}`;
|
||||
responseData = await quickBooksApiRequest.call(this, 'POST', endpoint, {}, body);
|
||||
responseData = responseData[capitalCase(resource)];
|
||||
|
||||
} else if (operation === 'void') {
|
||||
|
||||
// ----------------------------------
|
||||
// payment: void
|
||||
// ----------------------------------
|
||||
@@ -941,11 +975,8 @@ export class QuickBooks implements INodeType {
|
||||
const endpoint = `/v3/company/${companyId}/${resource}`;
|
||||
responseData = await quickBooksApiRequest.call(this, 'POST', endpoint, qs, {});
|
||||
responseData = responseData[capitalCase(resource)];
|
||||
|
||||
}
|
||||
|
||||
} else if (resource === 'purchase') {
|
||||
|
||||
// *********************************************************************
|
||||
// purchase
|
||||
// *********************************************************************
|
||||
@@ -953,7 +984,6 @@ export class QuickBooks implements INodeType {
|
||||
// https://developer.intuit.com/app/developer/qbo/docs/api/accounting/all-entities/purchase
|
||||
|
||||
if (operation === 'get') {
|
||||
|
||||
// ----------------------------------
|
||||
// purchase: get
|
||||
// ----------------------------------
|
||||
@@ -962,20 +992,15 @@ export class QuickBooks implements INodeType {
|
||||
const endpoint = `/v3/company/${companyId}/${resource}/${purchaseId}`;
|
||||
responseData = await quickBooksApiRequest.call(this, 'GET', endpoint, {}, {});
|
||||
responseData = responseData[capitalCase(resource)];
|
||||
|
||||
} else if (operation === 'getAll') {
|
||||
|
||||
// ----------------------------------
|
||||
// purchase: getAll
|
||||
// ----------------------------------
|
||||
|
||||
const endpoint = `/v3/company/${companyId}/query`;
|
||||
responseData = await handleListing.call(this, i, endpoint, resource);
|
||||
|
||||
}
|
||||
|
||||
} else if (resource === 'transaction') {
|
||||
|
||||
// *********************************************************************
|
||||
// transaction
|
||||
// *********************************************************************
|
||||
@@ -983,19 +1008,14 @@ export class QuickBooks implements INodeType {
|
||||
// https://developer.intuit.com/app/developer/qbo/docs/api/accounting/all-entities/transactionlist
|
||||
|
||||
if (operation === 'getReport') {
|
||||
|
||||
// ----------------------------------
|
||||
// transaction: getReport
|
||||
// ----------------------------------
|
||||
|
||||
const {
|
||||
columns,
|
||||
memo,
|
||||
term,
|
||||
customer,
|
||||
vendor,
|
||||
...rest
|
||||
} = this.getNodeParameter('filters', i) as TransactionFields;
|
||||
const { columns, memo, term, customer, vendor, ...rest } = this.getNodeParameter(
|
||||
'filters',
|
||||
i,
|
||||
) as TransactionFields;
|
||||
|
||||
let qs = { ...rest };
|
||||
|
||||
@@ -1034,9 +1054,7 @@ export class QuickBooks implements INodeType {
|
||||
responseData = simplifyTransactionReport(responseData);
|
||||
}
|
||||
}
|
||||
|
||||
} else if (resource === 'vendor') {
|
||||
|
||||
// *********************************************************************
|
||||
// vendor
|
||||
// *********************************************************************
|
||||
@@ -1044,7 +1062,6 @@ export class QuickBooks implements INodeType {
|
||||
// https://developer.intuit.com/app/developer/qbo/docs/api/accounting/most-commonly-used/vendor
|
||||
|
||||
if (operation === 'create') {
|
||||
|
||||
// ----------------------------------
|
||||
// vendor: create
|
||||
// ----------------------------------
|
||||
@@ -1060,9 +1077,7 @@ export class QuickBooks implements INodeType {
|
||||
const endpoint = `/v3/company/${companyId}/${resource}`;
|
||||
responseData = await quickBooksApiRequest.call(this, 'POST', endpoint, {}, body);
|
||||
responseData = responseData[capitalCase(resource)];
|
||||
|
||||
} else if (operation === 'get') {
|
||||
|
||||
// ----------------------------------
|
||||
// vendor: get
|
||||
// ----------------------------------
|
||||
@@ -1071,18 +1086,14 @@ export class QuickBooks implements INodeType {
|
||||
const endpoint = `/v3/company/${companyId}/${resource}/${vendorId}`;
|
||||
responseData = await quickBooksApiRequest.call(this, 'GET', endpoint, {}, {});
|
||||
responseData = responseData[capitalCase(resource)];
|
||||
|
||||
} else if (operation === 'getAll') {
|
||||
|
||||
// ----------------------------------
|
||||
// vendor: getAll
|
||||
// ----------------------------------
|
||||
|
||||
const endpoint = `/v3/company/${companyId}/query`;
|
||||
responseData = await handleListing.call(this, i, endpoint, resource);
|
||||
|
||||
} else if (operation === 'update') {
|
||||
|
||||
// ----------------------------------
|
||||
// vendor: update
|
||||
// ----------------------------------
|
||||
@@ -1096,7 +1107,11 @@ export class QuickBooks implements INodeType {
|
||||
const updateFields = this.getNodeParameter('updateFields', i) as IDataObject;
|
||||
|
||||
if (isEmpty(updateFields)) {
|
||||
throw new NodeOperationError(this.getNode(), `Please enter at least one field to update for the ${resource}.`, { itemIndex: i });
|
||||
throw new NodeOperationError(
|
||||
this.getNode(),
|
||||
`Please enter at least one field to update for the ${resource}.`,
|
||||
{ itemIndex: i },
|
||||
);
|
||||
}
|
||||
|
||||
body = populateFields.call(this, body, updateFields, resource);
|
||||
@@ -1104,22 +1119,24 @@ export class QuickBooks implements INodeType {
|
||||
const endpoint = `/v3/company/${companyId}/${resource}`;
|
||||
responseData = await quickBooksApiRequest.call(this, 'POST', endpoint, {}, body);
|
||||
responseData = responseData[capitalCase(resource)];
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
} catch (error) {
|
||||
if (this.continueOnFail()) {
|
||||
const download = this.getNodeParameter('download', 0, false) as boolean;
|
||||
if (['invoice', 'estimate', 'payment'].includes(resource) && ['get'].includes(operation) && download) {
|
||||
if (
|
||||
['invoice', 'estimate', 'payment'].includes(resource) &&
|
||||
['get'].includes(operation) &&
|
||||
download
|
||||
) {
|
||||
// in this case responseDate? === items
|
||||
if (!responseData){
|
||||
if (!responseData) {
|
||||
items[i].json = { error: error.message };
|
||||
responseData = items;
|
||||
}else {
|
||||
} else {
|
||||
responseData[i].json = { error: error.message };
|
||||
}
|
||||
}else {
|
||||
} else {
|
||||
returnData.push({ error: error.message });
|
||||
}
|
||||
continue;
|
||||
@@ -1134,11 +1151,14 @@ export class QuickBooks implements INodeType {
|
||||
|
||||
const download = this.getNodeParameter('download', 0, false) as boolean;
|
||||
|
||||
if (['invoice', 'estimate', 'payment'].includes(resource) && ['get'].includes(operation) && download) {
|
||||
if (
|
||||
['invoice', 'estimate', 'payment'].includes(resource) &&
|
||||
['get'].includes(operation) &&
|
||||
download
|
||||
) {
|
||||
return this.prepareOutputData(responseData);
|
||||
} else {
|
||||
return [this.helpers.returnJsonArray(returnData)];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user