Skip to content

Commit

Permalink
Fix payment id, add currency id, fix transaction matching
Browse files Browse the repository at this point in the history
  • Loading branch information
CodeShakingSheep committed Nov 1, 2024
1 parent 60c1ace commit 25a86a0
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,17 @@ export const bankTransactionFields: INodeProperties[] = [
],
default: '',
},
{
displayName: 'Currency',

Check failure on line 101 in packages/nodes-base/nodes/InvoiceNinja/BankTransactionDescription.ts

View workflow job for this annotation

GitHub Actions / Lint / Lint

End with '{Entity} Name or ID' [autofixable]
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

0 comments on commit 25a86a0

Please sign in to comment.