Refactor ING importer

This commit is contained in:
2025-04-03 18:17:56 +02:00
parent caf0a96ee0
commit df06c7c15c

View File

@@ -36,27 +36,21 @@ const headers = [
'unknown4', 'unknown4',
]; ];
const readIngTransaction = (data: string[]): IngTransaction|undefined => {
if (data.length !== headers.length) {
return;
}
const transaction: IngTransaction = {};
headers.forEach((key, index) => {
transaction[key] = data[index].trim();
});
return transaction;
};
export default class extends BaseTransactionParser<ParserConfig> { export default class extends BaseTransactionParser<ParserConfig> {
protected requiredFields = []; protected requiredFields = [];
#transactions: ValidatedIngTransaction[] = []; #transactions: ValidatedIngTransaction[] = [];
async pushTransaction(data: string[]): Promise<boolean> { async pushTransaction(data: string[]): Promise<boolean> {
const ing = readIngTransaction(data); if (data.length !== headers.length) {
return false;
}
const transaction: IngTransaction = {};
headers.forEach((key, index) => {
transaction[key] = data[index].trim();
});
if (!ing) { if (!transaction) {
return false; return false;
} }
@@ -65,18 +59,19 @@ export default class extends BaseTransactionParser<ParserConfig> {
return false; return false;
} }
const transactionAmount = parseAmount(ing.transactionAmount); const transactionAmount = parseAmount(transaction.transactionAmount);
const lockAmount = parseAmount(ing.lockAmount); const lockAmount = parseAmount(transaction.lockAmount);
if(transactionAmount === undefined && lockAmount === undefined) { if(transactionAmount === undefined && lockAmount === undefined) {
return false; return false;
} }
this.#transactions.push({ this.#transactions.push({
...ing, ...transaction,
transactionAmount, transactionAmount,
lockAmount, lockAmount,
} as ValidatedIngTransaction); } as ValidatedIngTransaction);
return true; return true;
} }