mirror of
https://github.com/n8n-io/n8n.git
synced 2024-12-31 15:37:26 -08:00
fix(Invoice Ninja Node): Fix actions for bank transactions (#11511)
This commit is contained in:
parent
d6b8e65abe
commit
80eea49cf0
|
@ -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',
|
||||
|
|
|
@ -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[];
|
||||
}
|
||||
|
|
|
@ -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<INodePropertyOptions[]> {
|
||||
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<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;
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
|
@ -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,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue