mirror of
https://github.com/maybe-finance/maybe.git
synced 2025-08-08 15:05:22 +02:00
fix teller sync issue
This commit is contained in:
parent
dc11e5254c
commit
55ffa013cb
4 changed files with 20 additions and 29 deletions
|
@ -140,7 +140,7 @@ syncInstitutionQueue.add(
|
|||
'sync-teller-institutions',
|
||||
{},
|
||||
{
|
||||
repeat: { cron: '0 0 */1 * *' }, // Run every 24 hours
|
||||
repeat: { cron: '0 */24 * * *' }, // Run every 24 hours
|
||||
}
|
||||
)
|
||||
|
||||
|
|
|
@ -163,27 +163,21 @@ export class TellerETL implements IETL<Connection, TellerRawData, TellerData> {
|
|||
|
||||
private async _extractTransactions(accessToken: string, accountIds: string[]) {
|
||||
const accountTransactions = await Promise.all(
|
||||
accountIds.map((accountId) =>
|
||||
SharedUtil.paginate({
|
||||
pageSize: 1000, // TODO: Check with Teller on max page size
|
||||
fetchData: async () => {
|
||||
const transactions = await SharedUtil.withRetry(
|
||||
() =>
|
||||
this.teller.getTransactions({
|
||||
accountId,
|
||||
accessToken: accessToken,
|
||||
}),
|
||||
{
|
||||
maxRetries: 3,
|
||||
}
|
||||
)
|
||||
accountIds.map(async (accountId) => {
|
||||
const transactions = await SharedUtil.withRetry(
|
||||
() =>
|
||||
this.teller.getTransactions({
|
||||
accountId,
|
||||
accessToken,
|
||||
}),
|
||||
{
|
||||
maxRetries: 3,
|
||||
}
|
||||
)
|
||||
|
||||
return transactions
|
||||
},
|
||||
})
|
||||
)
|
||||
return transactions
|
||||
})
|
||||
)
|
||||
|
||||
return accountTransactions.flat()
|
||||
}
|
||||
|
||||
|
@ -220,10 +214,10 @@ export class TellerETL implements IETL<Connection, TellerRawData, TellerData> {
|
|||
${transactionId},
|
||||
${date}::date,
|
||||
${description},
|
||||
${DbUtil.toDecimal(-amount)},
|
||||
${DbUtil.toDecimal(Number(amount))},
|
||||
${status === 'pending'},
|
||||
${'USD'},
|
||||
${details.counterparty.name ?? ''},
|
||||
${details.counterparty?.name ?? ''},
|
||||
${type},
|
||||
${details.category ?? ''}
|
||||
)`
|
||||
|
|
|
@ -11,7 +11,7 @@ import { Duration } from 'luxon'
|
|||
/**
|
||||
* Update this with the max window that Teller supports
|
||||
*/
|
||||
export const TELLER_WINDOW_MAX = Duration.fromObject({ years: 1 })
|
||||
export const TELLER_WINDOW_MAX = Duration.fromObject({ years: 2 })
|
||||
|
||||
export function getAccountBalanceData(
|
||||
{ balance, currency }: Pick<TellerTypes.AccountWithBalances, 'balance' | 'currency'>,
|
||||
|
@ -24,14 +24,11 @@ export function getAccountBalanceData(
|
|||
| 'availableBalanceStrategy'
|
||||
| 'currencyCode'
|
||||
> {
|
||||
const sign = classification === 'liability' ? -1 : 1
|
||||
return {
|
||||
currentBalanceProvider: new Prisma.Decimal(
|
||||
balance.ledger ? sign * Number(balance.ledger) : 0
|
||||
),
|
||||
currentBalanceProvider: new Prisma.Decimal(balance.ledger ? Number(balance.ledger) : 0),
|
||||
currentBalanceStrategy: 'current',
|
||||
availableBalanceProvider: new Prisma.Decimal(
|
||||
balance.available ? sign * Number(balance.available) : 0
|
||||
balance.available ? Number(balance.available) : 0
|
||||
),
|
||||
availableBalanceStrategy: 'available',
|
||||
currencyCode: currency,
|
||||
|
|
|
@ -38,7 +38,7 @@ export type Transaction = {
|
|||
details: {
|
||||
category?: DetailCategory
|
||||
processing_status: DetailProcessingStatus
|
||||
counterparty: {
|
||||
counterparty?: {
|
||||
name?: string
|
||||
type?: 'organization' | 'person'
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue