Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: catch errors on backfill #1909

Merged
merged 2 commits into from
Jan 30, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
82 changes: 43 additions & 39 deletions packages/wallet/backend/src/backfillTrxDetails.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,51 +31,55 @@ async function backfillTrxDetails() {
}

async function backfillCardTrx(account: Account) {
if (!account.cardId || !account.user?.gateHubUserId) {
return
}

let page = 1
const pageSize = 10
let shouldFetchNext = true
while (shouldFetchNext) {
const transactionsResponse = await gateHubClient.getCardTransactions(
account.cardId,
account.user.gateHubUserId,
pageSize,
page
)

if (transactionsResponse.data.length < pageSize) {
shouldFetchNext = false
try {
if (!account.cardId || !account.user?.gateHubUserId) {
return
}

for (const cardTrx of transactionsResponse.data) {
console.log('processing trx: ', cardTrx.id)
const existentTrx = await Transaction.query().findOne(
'paymentId',
cardTrx.id
let page = 1
const pageSize = 10
let shouldFetchNext = true
while (shouldFetchNext) {
const transactionsResponse = await gateHubClient.getCardTransactions(
account.cardId,
account.user.gateHubUserId,
pageSize,
page
)
if (!existentTrx) {
console.log('trx not found: ', cardTrx.id)
continue

if (transactionsResponse.data.length < pageSize) {
shouldFetchNext = false
}

await Transaction.query()
.where('id', existentTrx.id)
.update({
secondParty: cardTrx.merchantName,
txAmount: cardTrx.transactionAmount
? transformBalance(Number(cardTrx.transactionAmount), 2)
: undefined,
conversionRate: cardTrx.mastercardConversion?.convRate,
txCurrency: cardTrx.transactionCurrency,
cardTxType: cardTrx.type
})
console.log('trx updated: ', existentTrx.paymentId)
}
for (const cardTrx of transactionsResponse.data) {
console.log('processing trx: ', cardTrx.transactionId)
const existentTrx = await Transaction.query().findOne(
'paymentId',
cardTrx.transactionId
)
if (!existentTrx) {
console.log('trx not found: ', cardTrx.transactionId)
continue
}

await Transaction.query()
.where('id', existentTrx.id)
.update({
secondParty: cardTrx.merchantName,
txAmount: cardTrx.transactionAmount
? transformBalance(Number(cardTrx.transactionAmount), 2)
: undefined,
conversionRate: cardTrx.mastercardConversion?.convRate,
txCurrency: cardTrx.transactionCurrency,
cardTxType: cardTrx.type
})
console.log('trx updated: ', existentTrx.paymentId)
}

page++
page++
}
} catch (e) {
console.log('Failed to update trx for account: ', account.user.email)
}
}

Expand Down