mirror of
https://github.com/maybe-finance/maybe.git
synced 2025-08-09 15:35:22 +02:00
Merge pull request #192 from tmyracle/etl-fixes
This commit is contained in:
commit
ca54167285
1 changed files with 11 additions and 14 deletions
|
@ -100,10 +100,7 @@ export class TellerETL implements IETL<Connection, TellerRawData, TellerData> {
|
|||
|
||||
const accounts = await this._extractAccounts(accessToken)
|
||||
|
||||
const transactions = await this._extractTransactions(
|
||||
accessToken,
|
||||
accounts.map((a) => a.id)
|
||||
)
|
||||
const transactions = await this._extractTransactions(accessToken, accounts)
|
||||
|
||||
this.logger.info(
|
||||
`Extracted Teller data for customer ${user.tellerUserId} accounts=${accounts.length} transactions=${transactions.length}`,
|
||||
|
@ -196,26 +193,26 @@ export class TellerETL implements IETL<Connection, TellerRawData, TellerData> {
|
|||
]
|
||||
}
|
||||
|
||||
private async _extractTransactions(accessToken: string, accountIds: string[]) {
|
||||
private async _extractTransactions(
|
||||
accessToken: string,
|
||||
tellerAccounts: TellerTypes.GetAccountsResponse
|
||||
) {
|
||||
const accountTransactions = await Promise.all(
|
||||
accountIds.map(async (accountId) => {
|
||||
const account = await this.prisma.account.findFirst({
|
||||
where: {
|
||||
tellerAccountId: accountId,
|
||||
},
|
||||
})
|
||||
tellerAccounts.map(async (tellerAccount) => {
|
||||
const type = TellerUtil.getType(tellerAccount.type)
|
||||
const classification = AccountUtil.getClassification(type)
|
||||
|
||||
const transactions = await SharedUtil.withRetry(
|
||||
() =>
|
||||
this.teller.getTransactions({
|
||||
accountId,
|
||||
accountId: tellerAccount.id,
|
||||
accessToken,
|
||||
}),
|
||||
{
|
||||
maxRetries: 3,
|
||||
}
|
||||
)
|
||||
if (account!.classification === AccountClassification.asset) {
|
||||
if (classification === AccountClassification.asset) {
|
||||
transactions.forEach((t) => {
|
||||
t.amount = String(Number(t.amount) * -1)
|
||||
})
|
||||
|
@ -277,7 +274,7 @@ export class TellerETL implements IETL<Connection, TellerRawData, TellerData> {
|
|||
pending = EXCLUDED.pending,
|
||||
merchant_name = EXCLUDED.merchant_name,
|
||||
teller_type = EXCLUDED.teller_type,
|
||||
teller_category = EXCLUDED.teller_category;
|
||||
teller_category = EXCLUDED.teller_category,
|
||||
category = EXCLUDED.category;
|
||||
`
|
||||
})
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue