This repository has been archived by the owner on Oct 31, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
59 lines (42 loc) · 1.71 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
require('dotenv').config();
const {AuthManager} = require("./lib/AuthManager");
const {AccountManager} = require("./lib/AccountManager");
const {TransactionManager} = require("./lib/TransactionManager");
const fs = require('fs');
(async () => {
const authManager = new AuthManager();
await authManager.login();
await authManager.getAccessToken();
const accountManager = new AccountManager(authManager.accessToken, authManager.refreshToken);
const transactionManager = new TransactionManager(authManager.accessToken, authManager.refreshToken);
const formattedAccountsAndTx = [];
//Why an event approach on fetching list ?
//Because when we got a lot of data, we need to manage carefully the memory of the app
await accountManager.getAccounts(async (accounts) => {
for (const account of accounts) {
if (!account?.acc_number)
{
console.warn(`accNumber not available on account : ${JSON.stringify(account)}`);
continue;
}
await transactionManager.getTransactions(account.acc_number, async (txs) => {
const tmpFormattedAccountAndTX = {
acc_number: account?.acc_number,
amount: account?.amount,
transactions: []
};
for (const tx of txs) {
tmpFormattedAccountAndTX.transactions.push({
label: tx?.label,
amount: tx?.amount,
currency: tx?.currency
})
}
formattedAccountsAndTx.push(tmpFormattedAccountAndTX);
});
}
});
//Write the account list into file
await fs.writeFileSync('output.json', JSON.stringify(formattedAccountsAndTx));
console.log(formattedAccountsAndTx);
})();