mirror of
https://github.com/maybe-finance/maybe.git
synced 2025-08-09 07:25:19 +02:00
update sync path and add back sign for liability balance
This commit is contained in:
parent
d4b1ec6a94
commit
f6febecb52
4 changed files with 22 additions and 24 deletions
|
@ -3,7 +3,6 @@ import toast from 'react-hot-toast'
|
||||||
import { useAxiosWithAuth } from '../hooks/useAxiosWithAuth'
|
import { useAxiosWithAuth } from '../hooks/useAxiosWithAuth'
|
||||||
import { useMutation, useQueryClient } from '@tanstack/react-query'
|
import { useMutation, useQueryClient } from '@tanstack/react-query'
|
||||||
import type { SharedType } from '@maybe-finance/shared'
|
import type { SharedType } from '@maybe-finance/shared'
|
||||||
import { invalidateAccountQueries } from '../utils'
|
|
||||||
import type { AxiosInstance } from 'axios'
|
import type { AxiosInstance } from 'axios'
|
||||||
import type { TellerTypes } from '@maybe-finance/teller-api'
|
import type { TellerTypes } from '@maybe-finance/teller-api'
|
||||||
import { useAccountConnectionApi } from './useAccountConnectionApi'
|
import { useAccountConnectionApi } from './useAccountConnectionApi'
|
||||||
|
@ -57,9 +56,6 @@ export function useTellerApi() {
|
||||||
syncConnection.mutate(_connection.id)
|
syncConnection.mutate(_connection.id)
|
||||||
toast.success(`Account connection added!`)
|
toast.success(`Account connection added!`)
|
||||||
},
|
},
|
||||||
onSettled: () => {
|
|
||||||
invalidateAccountQueries(queryClient, false)
|
|
||||||
},
|
|
||||||
})
|
})
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
import type { AccountConnection, PrismaClient } from '@prisma/client'
|
import type { AccountConnection, PrismaClient } from '@prisma/client'
|
||||||
import type { Logger } from 'winston'
|
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 type { TellerApi, TellerTypes } from '@maybe-finance/teller-api'
|
||||||
import { DbUtil, TellerUtil, type IETL, type ICryptoService } from '@maybe-finance/server/shared'
|
import { DbUtil, TellerUtil, type IETL, type ICryptoService } from '@maybe-finance/server/shared'
|
||||||
import { Prisma } from '@prisma/client'
|
import { Prisma } from '@prisma/client'
|
||||||
|
@ -117,6 +117,9 @@ export class TellerETL implements IETL<Connection, TellerRawData, TellerData> {
|
||||||
return [
|
return [
|
||||||
// upsert accounts
|
// upsert accounts
|
||||||
...accounts.map((tellerAccount) => {
|
...accounts.map((tellerAccount) => {
|
||||||
|
const type = TellerUtil.getType(tellerAccount.type)
|
||||||
|
const classification = AccountUtil.getClassification(type)
|
||||||
|
|
||||||
return this.prisma.account.upsert({
|
return this.prisma.account.upsert({
|
||||||
where: {
|
where: {
|
||||||
accountConnectionId_tellerAccountId: {
|
accountConnectionId_tellerAccountId: {
|
||||||
|
@ -136,7 +139,7 @@ export class TellerETL implements IETL<Connection, TellerRawData, TellerData> {
|
||||||
tellerType: tellerAccount.type,
|
tellerType: tellerAccount.type,
|
||||||
tellerSubtype: tellerAccount.subtype,
|
tellerSubtype: tellerAccount.subtype,
|
||||||
mask: tellerAccount.last_four,
|
mask: tellerAccount.last_four,
|
||||||
...TellerUtil.getAccountBalanceData(tellerAccount),
|
...TellerUtil.getAccountBalanceData(tellerAccount, classification),
|
||||||
},
|
},
|
||||||
update: {
|
update: {
|
||||||
type: TellerUtil.getType(tellerAccount.type),
|
type: TellerUtil.getType(tellerAccount.type),
|
||||||
|
@ -144,7 +147,7 @@ export class TellerETL implements IETL<Connection, TellerRawData, TellerData> {
|
||||||
subcategoryProvider: tellerAccount.subtype ?? 'other',
|
subcategoryProvider: tellerAccount.subtype ?? 'other',
|
||||||
tellerType: tellerAccount.type,
|
tellerType: tellerAccount.type,
|
||||||
tellerSubtype: tellerAccount.subtype,
|
tellerSubtype: tellerAccount.subtype,
|
||||||
..._.omit(TellerUtil.getAccountBalanceData(tellerAccount), [
|
..._.omit(TellerUtil.getAccountBalanceData(tellerAccount, classification), [
|
||||||
'currentBalanceStrategy',
|
'currentBalanceStrategy',
|
||||||
'availableBalanceStrategy',
|
'availableBalanceStrategy',
|
||||||
]),
|
]),
|
||||||
|
|
|
@ -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
|
return accountConnection
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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 type { TellerTypes } from '@maybe-finance/teller-api'
|
||||||
import { Duration } from 'luxon'
|
import { Duration } from 'luxon'
|
||||||
|
|
||||||
|
@ -7,10 +13,10 @@ import { Duration } from 'luxon'
|
||||||
*/
|
*/
|
||||||
export const TELLER_WINDOW_MAX = Duration.fromObject({ years: 1 })
|
export const TELLER_WINDOW_MAX = Duration.fromObject({ years: 1 })
|
||||||
|
|
||||||
export function getAccountBalanceData({
|
export function getAccountBalanceData(
|
||||||
balance,
|
{ balance, currency }: Pick<TellerTypes.AccountWithBalances, 'balance' | 'currency'>,
|
||||||
currency,
|
classification: AccountClassification
|
||||||
}: Pick<TellerTypes.AccountWithBalances, 'balance' | 'currency'>): Pick<
|
): Pick<
|
||||||
Account,
|
Account,
|
||||||
| 'currentBalanceProvider'
|
| 'currentBalanceProvider'
|
||||||
| 'currentBalanceStrategy'
|
| 'currentBalanceStrategy'
|
||||||
|
@ -18,11 +24,14 @@ export function getAccountBalanceData({
|
||||||
| 'availableBalanceStrategy'
|
| 'availableBalanceStrategy'
|
||||||
| 'currencyCode'
|
| 'currencyCode'
|
||||||
> {
|
> {
|
||||||
|
const sign = classification === 'liability' ? -1 : 1
|
||||||
return {
|
return {
|
||||||
currentBalanceProvider: new Prisma.Decimal(balance.ledger ? Number(balance.ledger) : 0),
|
currentBalanceProvider: new Prisma.Decimal(
|
||||||
|
balance.ledger ? sign * Number(balance.ledger) : 0
|
||||||
|
),
|
||||||
currentBalanceStrategy: 'current',
|
currentBalanceStrategy: 'current',
|
||||||
availableBalanceProvider: new Prisma.Decimal(
|
availableBalanceProvider: new Prisma.Decimal(
|
||||||
balance.available ? Number(balance.available) : 0
|
balance.available ? sign * Number(balance.available) : 0
|
||||||
),
|
),
|
||||||
availableBalanceStrategy: 'available',
|
availableBalanceStrategy: 'available',
|
||||||
currencyCode: currency,
|
currencyCode: currency,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue