From 25a86a0d291120d097af94c0337cd57a0dd8d35f Mon Sep 17 00:00:00 2001 From: CodeShakingSheep <19874562+CodeShakingSheep@users.noreply.github.com> Date: Fri, 1 Nov 2024 16:26:45 -0500 Subject: [PATCH] Fix payment id, add currency id, fix transaction matching --- .../BankTransactionDescription.ts | 11 +++++ .../InvoiceNinja/BankTransactionInterface.ts | 7 +++- .../nodes/InvoiceNinja/InvoiceNinja.node.ts | 40 ++++++++++++++++--- 3 files changed, 51 insertions(+), 7 deletions(-) diff --git a/packages/nodes-base/nodes/InvoiceNinja/BankTransactionDescription.ts b/packages/nodes-base/nodes/InvoiceNinja/BankTransactionDescription.ts index abf39ab493889..856cdd0a8f9bc 100644 --- a/packages/nodes-base/nodes/InvoiceNinja/BankTransactionDescription.ts +++ b/packages/nodes-base/nodes/InvoiceNinja/BankTransactionDescription.ts @@ -97,6 +97,17 @@ export const bankTransactionFields: INodeProperties[] = [ ], default: '', }, + { + displayName: 'Currency', + name: 'currencyId', + type: 'options', + description: + 'Choose from the list, or specify an ID using an expression', + typeOptions: { + loadOptionsMethod: 'getCurrencies', + }, + default: '', + }, { displayName: 'Date', name: 'date', diff --git a/packages/nodes-base/nodes/InvoiceNinja/BankTransactionInterface.ts b/packages/nodes-base/nodes/InvoiceNinja/BankTransactionInterface.ts index 735f339ab8c4e..385009aec6e7d 100644 --- a/packages/nodes-base/nodes/InvoiceNinja/BankTransactionInterface.ts +++ b/packages/nodes-base/nodes/InvoiceNinja/BankTransactionInterface.ts @@ -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[]; } diff --git a/packages/nodes-base/nodes/InvoiceNinja/InvoiceNinja.node.ts b/packages/nodes-base/nodes/InvoiceNinja/InvoiceNinja.node.ts index ef7494d30693c..f587701296177 100644 --- a/packages/nodes-base/nodes/InvoiceNinja/InvoiceNinja.node.ts +++ b/packages/nodes-base/nodes/InvoiceNinja/InvoiceNinja.node.ts @@ -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 = { @@ -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 { const returnData: INodePropertyOptions[] = []; @@ -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 { + 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; + }, }, }; @@ -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; } @@ -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, ); } }