Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(Invoice Ninja Node): Fix actions for bank transactions #11511

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,17 @@ export const bankTransactionFields: INodeProperties[] = [
],
default: '',
},
{
displayName: 'Currency Name or ID',
name: 'currencyId',
type: 'options',
description:
'Choose from the list, or specify an ID using an <a href="https://docs.n8n.io/code/expressions/">expression</a>',
typeOptions: {
loadOptionsMethod: 'getCurrencies',
},
default: '',
},
{
displayName: 'Date',
name: 'date',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,13 @@ export interface IBankTransaction {
amount?: number;
bank_integration_id?: number;
base_type?: string;
currency_id?: number;
date?: string;
description?: string;
id?: string;
paymentId?: string;
payment_id?: string;
}

export interface IBankTransactions {
transactions: IBankTransaction[];
}
40 changes: 34 additions & 6 deletions packages/nodes-base/nodes/InvoiceNinja/InvoiceNinja.node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ import { isoCountryCodes } from '@utils/ISOCountryCodes';

import { bankTransactionFields, bankTransactionOperations } from './BankTransactionDescription';

import type { IBankTransaction } from './BankTransactionInterface';
import type { IBankTransaction, IBankTransactions } from './BankTransactionInterface';

export class InvoiceNinja implements INodeType {
description: INodeTypeDescription = {
Expand Down Expand Up @@ -295,7 +295,7 @@ export class InvoiceNinja implements INodeType {
}
return returnData;
},
// Get all the available users to display them to user so that they can
// Get all the matchable payments to display them to user so that they can
// select them easily
async getPayments(this: ILoadOptionsFunctions): Promise<INodePropertyOptions[]> {
const returnData: INodePropertyOptions[] = [];
Expand All @@ -322,6 +322,29 @@ export class InvoiceNinja implements INodeType {
}
return returnData;
},
// Get all the currencies to display them to user so that they can
// select them easily
async getCurrencies(this: ILoadOptionsFunctions): Promise<INodePropertyOptions[]> {
const returnData: INodePropertyOptions[] = [];

const statics = await invoiceNinjaApiRequestAllItems.call(this, 'data', 'GET', '/statics');

Object.entries(statics)
.filter(([key]) => key === 'currencies')
.forEach(([key, value]) => {
if (key === 'currencies' && Array.isArray(value)) {
for (const currency of value) {
const currencyName = [currency.number, currency.code].filter((e) => e).join(' - ');
const currencyId = currency.id as string;
returnData.push({
name: currencyName,
value: currencyId,
});
}
}
});
return returnData;
},
},
};

Expand Down Expand Up @@ -986,6 +1009,9 @@ export class InvoiceNinja implements INodeType {
if (additionalFields.client) {
body.date = additionalFields.date as string;
}
if (additionalFields.currencyId) {
body.currency_id = additionalFields.currencyId as number;
}
if (additionalFields.email) {
body.description = additionalFields.description as string;
}
Expand Down Expand Up @@ -1054,18 +1080,20 @@ export class InvoiceNinja implements INodeType {
if (operation === 'matchPayment') {
const bankTransactionId = this.getNodeParameter('bankTransactionId', i) as string;
const paymentId = this.getNodeParameter('paymentId', i) as string;
const body: IBankTransaction = {};
const body: IBankTransactions = { transactions: [] };
const bankTransaction: IBankTransaction = {};
if (bankTransactionId) {
body.id = bankTransactionId;
bankTransaction.id = bankTransactionId as string;
}
if (paymentId) {
body.paymentId = paymentId;
bankTransaction.payment_id = paymentId as string;
}
body.transactions.push(bankTransaction);
responseData = await invoiceNinjaApiRequest.call(
this,
'POST',
`${resourceEndpoint}/match`,
body as IDataObject,
body as unknown as IDataObject,
);
}
}
Expand Down