mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-17 18:12:04 +00:00
fix(InvoiceNinja Node): added support for v5
This commit is contained in:
@@ -43,7 +43,7 @@ export class InvoiceNinja implements INodeType {
|
||||
name: 'invoiceNinja',
|
||||
icon: 'file:invoiceNinja.svg',
|
||||
group: ['output'],
|
||||
version: 1,
|
||||
version: [1, 2],
|
||||
subtitle: '={{$parameter["operation"] + ": " + $parameter["resource"]}}',
|
||||
description: 'Consume Invoice Ninja API',
|
||||
defaults: {
|
||||
@@ -58,6 +58,50 @@ export class InvoiceNinja implements INodeType {
|
||||
},
|
||||
],
|
||||
properties: [
|
||||
{
|
||||
displayName: 'API Version',
|
||||
name: 'apiVersion',
|
||||
type: 'options',
|
||||
isNodeSetting: true,
|
||||
displayOptions: {
|
||||
show: {
|
||||
'@version': [1],
|
||||
},
|
||||
},
|
||||
options: [
|
||||
{
|
||||
name: 'Version 4',
|
||||
value: 'v4',
|
||||
},
|
||||
{
|
||||
name: 'Version 5',
|
||||
value: 'v5',
|
||||
},
|
||||
],
|
||||
default: 'v4',
|
||||
},
|
||||
{
|
||||
displayName: 'API Version',
|
||||
name: 'apiVersion',
|
||||
type: 'options',
|
||||
isNodeSetting: true,
|
||||
displayOptions: {
|
||||
show: {
|
||||
'@version': [2],
|
||||
},
|
||||
},
|
||||
options: [
|
||||
{
|
||||
name: 'Version 4',
|
||||
value: 'v4',
|
||||
},
|
||||
{
|
||||
name: 'Version 5',
|
||||
value: 'v5',
|
||||
},
|
||||
],
|
||||
default: 'v5',
|
||||
},
|
||||
{
|
||||
displayName: 'Resource',
|
||||
name: 'resource',
|
||||
@@ -114,8 +158,8 @@ export class InvoiceNinja implements INodeType {
|
||||
const returnData: INodePropertyOptions[] = [];
|
||||
const clients = await invoiceNinjaApiRequestAllItems.call(this, 'data', 'GET', '/clients');
|
||||
for (const client of clients) {
|
||||
const clientName = client.display_name;
|
||||
const clientId = client.id;
|
||||
const clientName = client.display_name as string;
|
||||
const clientId = client.id as string;
|
||||
returnData.push({
|
||||
name: clientName,
|
||||
value: clientId,
|
||||
@@ -134,8 +178,8 @@ export class InvoiceNinja implements INodeType {
|
||||
'/projects',
|
||||
);
|
||||
for (const project of projects) {
|
||||
const projectName = project.name;
|
||||
const projectId = project.id;
|
||||
const projectName = project.name as string;
|
||||
const projectId = project.id as string;
|
||||
returnData.push({
|
||||
name: projectName,
|
||||
value: projectId,
|
||||
@@ -154,8 +198,8 @@ export class InvoiceNinja implements INodeType {
|
||||
'/invoices',
|
||||
);
|
||||
for (const invoice of invoices) {
|
||||
const invoiceName = invoice.invoice_number;
|
||||
const invoiceId = invoice.id;
|
||||
const invoiceName = (invoice.invoice_number || invoice.number) as string;
|
||||
const invoiceId = invoice.id as string;
|
||||
returnData.push({
|
||||
name: invoiceName,
|
||||
value: invoiceId,
|
||||
@@ -183,8 +227,8 @@ export class InvoiceNinja implements INodeType {
|
||||
const returnData: INodePropertyOptions[] = [];
|
||||
const vendors = await invoiceNinjaApiRequestAllItems.call(this, 'data', 'GET', '/vendors');
|
||||
for (const vendor of vendors) {
|
||||
const vendorName = vendor.name;
|
||||
const vendorId = vendor.id;
|
||||
const vendorName = vendor.name as string;
|
||||
const vendorId = vendor.id as string;
|
||||
returnData.push({
|
||||
name: vendorName,
|
||||
value: vendorId,
|
||||
@@ -203,8 +247,8 @@ export class InvoiceNinja implements INodeType {
|
||||
'/expense_categories',
|
||||
);
|
||||
for (const category of categories) {
|
||||
const categoryName = category.name;
|
||||
const categoryId = category.id;
|
||||
const categoryName = category.name as string;
|
||||
const categoryId = category.id as string;
|
||||
returnData.push({
|
||||
name: categoryName,
|
||||
value: categoryId,
|
||||
@@ -219,10 +263,14 @@ export class InvoiceNinja implements INodeType {
|
||||
const items = this.getInputData();
|
||||
const returnData: INodeExecutionData[] = [];
|
||||
const length = items.length;
|
||||
let responseData;
|
||||
const qs: IDataObject = {};
|
||||
|
||||
let responseData;
|
||||
|
||||
const resource = this.getNodeParameter('resource', 0) as string;
|
||||
const operation = this.getNodeParameter('operation', 0) as string;
|
||||
const apiVersion = this.getNodeParameter('apiVersion', 0) as string;
|
||||
|
||||
for (let i = 0; i < length; i++) {
|
||||
//Routes: https://github.com/invoiceninja/invoiceninja/blob/ff455c8ed9fd0c0326956175ecd509efa8bad263/routes/api.php
|
||||
try {
|
||||
@@ -291,7 +339,12 @@ export class InvoiceNinja implements INodeType {
|
||||
body.postal_code = billingAddressValue.postalCode as string;
|
||||
body.country_id = parseInt(billingAddressValue.countryCode as string, 10);
|
||||
}
|
||||
responseData = await invoiceNinjaApiRequest.call(this, 'POST', '/clients', body);
|
||||
responseData = await invoiceNinjaApiRequest.call(
|
||||
this,
|
||||
'POST',
|
||||
'/clients',
|
||||
body as IDataObject,
|
||||
);
|
||||
responseData = responseData.data;
|
||||
}
|
||||
if (operation === 'get') {
|
||||
@@ -429,14 +482,28 @@ export class InvoiceNinja implements INodeType {
|
||||
}
|
||||
body.invoice_items = items;
|
||||
}
|
||||
responseData = await invoiceNinjaApiRequest.call(this, 'POST', '/invoices', body);
|
||||
responseData = await invoiceNinjaApiRequest.call(
|
||||
this,
|
||||
'POST',
|
||||
'/invoices',
|
||||
body as IDataObject,
|
||||
);
|
||||
responseData = responseData.data;
|
||||
}
|
||||
if (operation === 'email') {
|
||||
const invoiceId = this.getNodeParameter('invoiceId', i) as string;
|
||||
responseData = await invoiceNinjaApiRequest.call(this, 'POST', '/email_invoice', {
|
||||
id: invoiceId,
|
||||
});
|
||||
if (apiVersion === 'v4') {
|
||||
responseData = await invoiceNinjaApiRequest.call(this, 'POST', '/email_invoice', {
|
||||
id: invoiceId,
|
||||
});
|
||||
}
|
||||
if (apiVersion === 'v5') {
|
||||
responseData = await invoiceNinjaApiRequest.call(
|
||||
this,
|
||||
'GET',
|
||||
`/invoices/${invoiceId}/email`,
|
||||
);
|
||||
}
|
||||
}
|
||||
if (operation === 'get') {
|
||||
const invoiceId = this.getNodeParameter('invoiceId', i) as string;
|
||||
@@ -526,7 +593,12 @@ export class InvoiceNinja implements INodeType {
|
||||
}
|
||||
body.time_log = JSON.stringify(logs);
|
||||
}
|
||||
responseData = await invoiceNinjaApiRequest.call(this, 'POST', '/tasks', body);
|
||||
responseData = await invoiceNinjaApiRequest.call(
|
||||
this,
|
||||
'POST',
|
||||
'/tasks',
|
||||
body as IDataObject,
|
||||
);
|
||||
responseData = responseData.data;
|
||||
}
|
||||
if (operation === 'get') {
|
||||
@@ -575,10 +647,14 @@ export class InvoiceNinja implements INodeType {
|
||||
if (operation === 'create') {
|
||||
const additionalFields = this.getNodeParameter('additionalFields', i) as IDataObject;
|
||||
const invoice = this.getNodeParameter('invoice', i) as number;
|
||||
const client = (
|
||||
await invoiceNinjaApiRequest.call(this, 'GET', `/invoices/${invoice}`, {}, qs)
|
||||
).data?.client_id as string;
|
||||
const amount = this.getNodeParameter('amount', i) as number;
|
||||
const body: IPayment = {
|
||||
invoice_id: invoice,
|
||||
amount,
|
||||
client_id: client,
|
||||
};
|
||||
if (additionalFields.paymentType) {
|
||||
body.payment_type_id = additionalFields.paymentType as number;
|
||||
@@ -589,7 +665,12 @@ export class InvoiceNinja implements INodeType {
|
||||
if (additionalFields.privateNotes) {
|
||||
body.private_notes = additionalFields.privateNotes as string;
|
||||
}
|
||||
responseData = await invoiceNinjaApiRequest.call(this, 'POST', '/payments', body);
|
||||
responseData = await invoiceNinjaApiRequest.call(
|
||||
this,
|
||||
'POST',
|
||||
'/payments',
|
||||
body as IDataObject,
|
||||
);
|
||||
responseData = responseData.data;
|
||||
}
|
||||
if (operation === 'get') {
|
||||
@@ -693,7 +774,12 @@ export class InvoiceNinja implements INodeType {
|
||||
if (additionalFields.vendor) {
|
||||
body.vendor_id = additionalFields.vendor as number;
|
||||
}
|
||||
responseData = await invoiceNinjaApiRequest.call(this, 'POST', '/expenses', body);
|
||||
responseData = await invoiceNinjaApiRequest.call(
|
||||
this,
|
||||
'POST',
|
||||
'/expenses',
|
||||
body as IDataObject,
|
||||
);
|
||||
responseData = responseData.data;
|
||||
}
|
||||
if (operation === 'get') {
|
||||
@@ -735,6 +821,7 @@ export class InvoiceNinja implements INodeType {
|
||||
}
|
||||
}
|
||||
if (resource === 'quote') {
|
||||
const resourceEndpoint = apiVersion === 'v4' ? '/invoices' : '/quotes';
|
||||
if (operation === 'create') {
|
||||
const additionalFields = this.getNodeParameter('additionalFields', i) as IDataObject;
|
||||
const body: IQuote = {
|
||||
@@ -825,14 +912,28 @@ export class InvoiceNinja implements INodeType {
|
||||
}
|
||||
body.invoice_items = items;
|
||||
}
|
||||
responseData = await invoiceNinjaApiRequest.call(this, 'POST', '/invoices', body);
|
||||
responseData = await invoiceNinjaApiRequest.call(
|
||||
this,
|
||||
'POST',
|
||||
resourceEndpoint,
|
||||
body as IDataObject,
|
||||
);
|
||||
responseData = responseData.data;
|
||||
}
|
||||
if (operation === 'email') {
|
||||
const quoteId = this.getNodeParameter('quoteId', i) as string;
|
||||
responseData = await invoiceNinjaApiRequest.call(this, 'POST', '/email_invoice', {
|
||||
id: quoteId,
|
||||
});
|
||||
if (apiVersion === 'v4') {
|
||||
responseData = await invoiceNinjaApiRequest.call(this, 'POST', '/email_invoice', {
|
||||
id: quoteId,
|
||||
});
|
||||
}
|
||||
if (apiVersion === 'v5') {
|
||||
responseData = await invoiceNinjaApiRequest.call(
|
||||
this,
|
||||
'GET',
|
||||
`/quotes/${quoteId}/email`,
|
||||
);
|
||||
}
|
||||
}
|
||||
if (operation === 'get') {
|
||||
const quoteId = this.getNodeParameter('quoteId', i) as string;
|
||||
@@ -843,7 +944,7 @@ export class InvoiceNinja implements INodeType {
|
||||
responseData = await invoiceNinjaApiRequest.call(
|
||||
this,
|
||||
'GET',
|
||||
`/invoices/${quoteId}`,
|
||||
`${resourceEndpoint}/${quoteId}`,
|
||||
{},
|
||||
qs,
|
||||
);
|
||||
@@ -878,7 +979,7 @@ export class InvoiceNinja implements INodeType {
|
||||
responseData = await invoiceNinjaApiRequest.call(
|
||||
this,
|
||||
'DELETE',
|
||||
`/invoices/${quoteId}`,
|
||||
`${resourceEndpoint}/${quoteId}`,
|
||||
);
|
||||
responseData = responseData.data;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user