synt_backend
Version:
Synt light-weight node backend service
34 lines (31 loc) • 882 B
JavaScript
import { createClient } from "../helpers/ibanity";
export async function getBankTransactionsDB({ t, User, VME }) {
// ibanity client
try {
const client = await createClient({ VME, User });
let response = await client.getAccounts();
if (response.success) {
let accounts = response.data;
let array = [];
for (const a of accounts) {
let resp = await client.getTransactions(a.id);
if (resp.success) {
array.push({
id: a.id,
...a.attributes,
transactions: resp.data.map((t) => ({ ...t.attributes })),
});
}
}
return {
success: true,
message: t("api.banking.messages.bankUpdated", "Bank updated..."),
accounts: array,
};
} else {
return response;
}
} catch (err) {
return { success: false, error: err };
}
}