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

update sync path and add back sign for liability balance

This commit is contained in:
Tyler Myracle 2024-01-17 13:53:09 -06:00
parent d4b1ec6a94
commit f6febecb52
4 changed files with 22 additions and 24 deletions

View file

@ -3,7 +3,6 @@ import toast from 'react-hot-toast'
import { useAxiosWithAuth } from '../hooks/useAxiosWithAuth'
import { useMutation, useQueryClient } from '@tanstack/react-query'
import type { SharedType } from '@maybe-finance/shared'
import { invalidateAccountQueries } from '../utils'
import type { AxiosInstance } from 'axios'
import type { TellerTypes } from '@maybe-finance/teller-api'
import { useAccountConnectionApi } from './useAccountConnectionApi'
@ -57,9 +56,6 @@ export function useTellerApi() {
syncConnection.mutate(_connection.id)
toast.success(`Account connection added!`)
},
onSettled: () => {
invalidateAccountQueries(queryClient, false)
},
})
return {

View file

@ -1,6 +1,6 @@
import type { AccountConnection, PrismaClient } from '@prisma/client'
import type { Logger } from 'winston'
import { 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 { DbUtil, TellerUtil, type IETL, type ICryptoService } from '@maybe-finance/server/shared'
import { Prisma } from '@prisma/client'
@ -117,6 +117,9 @@ export class TellerETL implements IETL<Connection, TellerRawData, TellerData> {
return [
// upsert accounts
...accounts.map((tellerAccount) => {
const type = TellerUtil.getType(tellerAccount.type)
const classification = AccountUtil.getClassification(type)
return this.prisma.account.upsert({
where: {
accountConnectionId_tellerAccountId: {
@ -136,7 +139,7 @@ export class TellerETL implements IETL<Connection, TellerRawData, TellerData> {
tellerType: tellerAccount.type,
tellerSubtype: tellerAccount.subtype,
mask: tellerAccount.last_four,
...TellerUtil.getAccountBalanceData(tellerAccount),
...TellerUtil.getAccountBalanceData(tellerAccount, classification),
},
update: {
type: TellerUtil.getType(tellerAccount.type),
@ -144,7 +147,7 @@ export class TellerETL implements IETL<Connection, TellerRawData, TellerData> {
subcategoryProvider: tellerAccount.subtype ?? 'other',
tellerType: tellerAccount.type,
tellerSubtype: tellerAccount.subtype,
..._.omit(TellerUtil.getAccountBalanceData(tellerAccount), [
..._.omit(TellerUtil.getAccountBalanceData(tellerAccount, classification), [
'currentBalanceStrategy',
'availableBalanceStrategy',
]),

View file

@ -168,16 +168,6 @@ export class TellerService implements IAccountConnectionProvider, IInstitutionPr
},
})
await this.sync(accountConnection, { type: 'teller', initialSync: true })
await this.prisma.accountConnection.update({
where: { id: accountConnection.id },
data: {
status: 'OK',
syncStatus: 'IDLE',
},
})
return accountConnection
}
}

View file

@ -1,4 +1,10 @@
import { Prisma, AccountCategory, AccountType, type Account } from '@prisma/client'
import {
Prisma,
AccountCategory,
AccountType,
type Account,
type AccountClassification,
} from '@prisma/client'
import type { TellerTypes } from '@maybe-finance/teller-api'
import { Duration } from 'luxon'
@ -7,10 +13,10 @@ import { Duration } from 'luxon'
*/
export const TELLER_WINDOW_MAX = Duration.fromObject({ years: 1 })
export function getAccountBalanceData({
balance,
currency,
}: Pick<TellerTypes.AccountWithBalances, 'balance' | 'currency'>): Pick<
export function getAccountBalanceData(
{ balance, currency }: Pick<TellerTypes.AccountWithBalances, 'balance' | 'currency'>,
classification: AccountClassification
): Pick<
Account,
| 'currentBalanceProvider'
| 'currentBalanceStrategy'
@ -18,11 +24,14 @@ export function getAccountBalanceData({
| 'availableBalanceStrategy'
| 'currencyCode'
> {
const sign = classification === 'liability' ? -1 : 1
return {
currentBalanceProvider: new Prisma.Decimal(balance.ledger ? Number(balance.ledger) : 0),
currentBalanceProvider: new Prisma.Decimal(
balance.ledger ? sign * Number(balance.ledger) : 0
),
currentBalanceStrategy: 'current',
availableBalanceProvider: new Prisma.Decimal(
balance.available ? Number(balance.available) : 0
balance.available ? sign * Number(balance.available) : 0
),
availableBalanceStrategy: 'available',
currencyCode: currency,