1
0
Fork 0
mirror of https://github.com/maybe-finance/maybe.git synced 2025-08-09 15:35:22 +02:00

fun fixes

This commit is contained in:
Tyler Myracle 2024-01-20 23:17:02 -06:00
parent 0d5d7d5a7f
commit b066baef5f

View file

@ -100,10 +100,7 @@ export class TellerETL implements IETL<Connection, TellerRawData, TellerData> {
const accounts = await this._extractAccounts(accessToken) const accounts = await this._extractAccounts(accessToken)
const transactions = await this._extractTransactions( const transactions = await this._extractTransactions(accessToken, accounts)
accessToken,
accounts.map((a) => a.id)
)
this.logger.info( this.logger.info(
`Extracted Teller data for customer ${user.tellerUserId} accounts=${accounts.length} transactions=${transactions.length}`, `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( const accountTransactions = await Promise.all(
accountIds.map(async (accountId) => { tellerAccounts.map(async (tellerAccount) => {
const account = await this.prisma.account.findFirst({ const type = TellerUtil.getType(tellerAccount.type)
where: { const classification = AccountUtil.getClassification(type)
tellerAccountId: accountId,
},
})
const transactions = await SharedUtil.withRetry( const transactions = await SharedUtil.withRetry(
() => () =>
this.teller.getTransactions({ this.teller.getTransactions({
accountId, accountId: tellerAccount.id,
accessToken, accessToken,
}), }),
{ {
maxRetries: 3, maxRetries: 3,
} }
) )
if (account!.classification === AccountClassification.asset) { if (classification === AccountClassification.asset) {
transactions.forEach((t) => { transactions.forEach((t) => {
t.amount = String(Number(t.amount) * -1) t.amount = String(Number(t.amount) * -1)
}) })
@ -277,7 +274,7 @@ export class TellerETL implements IETL<Connection, TellerRawData, TellerData> {
pending = EXCLUDED.pending, pending = EXCLUDED.pending,
merchant_name = EXCLUDED.merchant_name, merchant_name = EXCLUDED.merchant_name,
teller_type = EXCLUDED.teller_type, teller_type = EXCLUDED.teller_type,
teller_category = EXCLUDED.teller_category; teller_category = EXCLUDED.teller_category,
category = EXCLUDED.category; category = EXCLUDED.category;
` `
}) })