1
0
Fork 0
mirror of https://github.com/maybe-finance/maybe.git synced 2025-08-09 07:25:19 +02:00
This commit is contained in:
Tyler Myracle 2024-01-20 12:06:50 -06:00
parent df7e83efe7
commit 14b45aee2b
2 changed files with 16 additions and 8 deletions

View file

@ -1,4 +1,5 @@
import type { AccountConnection, PrismaClient } from '@prisma/client' import type { AccountConnection, PrismaClient } from '@prisma/client'
import { AccountClassification } from '@prisma/client'
import type { Logger } from 'winston' import type { Logger } from 'winston'
import { AccountUtil, SharedUtil, type SharedType } from '@maybe-finance/shared' import { AccountUtil, SharedUtil, type SharedType } from '@maybe-finance/shared'
import type { TellerApi, TellerTypes } from '@maybe-finance/teller-api' import type { TellerApi, TellerTypes } from '@maybe-finance/teller-api'
@ -164,6 +165,12 @@ export class TellerETL implements IETL<Connection, TellerRawData, TellerData> {
private async _extractTransactions(accessToken: string, accountIds: string[]) { private async _extractTransactions(accessToken: string, accountIds: string[]) {
const accountTransactions = await Promise.all( const accountTransactions = await Promise.all(
accountIds.map(async (accountId) => { accountIds.map(async (accountId) => {
const account = await this.prisma.account.findFirst({
where: {
tellerAccountId: accountId,
},
})
const transactions = await SharedUtil.withRetry( const transactions = await SharedUtil.withRetry(
() => () =>
this.teller.getTransactions({ this.teller.getTransactions({
@ -174,6 +181,11 @@ export class TellerETL implements IETL<Connection, TellerRawData, TellerData> {
maxRetries: 3, maxRetries: 3,
} }
) )
if (account!.classification === AccountClassification.liability) {
transactions.forEach((t) => {
t.amount = String(Number(t.amount) * -1)
})
}
return transactions return transactions
}) })
@ -214,7 +226,7 @@ export class TellerETL implements IETL<Connection, TellerRawData, TellerData> {
${transactionId}, ${transactionId},
${date}::date, ${date}::date,
${description}, ${description},
${DbUtil.toDecimal(Number(amount))}, ${DbUtil.toDecimal(Number(-amount))},
${status === 'pending'}, ${status === 'pending'},
${'USD'}, ${'USD'},
${details.counterparty?.name ?? ''}, ${details.counterparty?.name ?? ''},

View file

@ -1,10 +1,6 @@
import { import { Prisma, AccountCategory, AccountType } from '@prisma/client'
Prisma, import type { AccountClassification } from '@prisma/client'
AccountCategory, import type { Account } from '@prisma/client'
AccountType,
type Account,
type AccountClassification,
} from '@prisma/client'
import type { TellerTypes } from '@maybe-finance/teller-api' import type { TellerTypes } from '@maybe-finance/teller-api'
import { Duration } from 'luxon' import { Duration } from 'luxon'