fix(reconcile): pass customerCode (not helcimCustomerId) to Helcim transactions API
Some checks failed
Test / vitest (push) Successful in 11m5s
Test / playwright (push) Has been cancelled
Test / Notify on failure (push) Blocked by required conditions
Test / visual (push) Blocked by required conditions

This commit is contained in:
Jennie Robinson Faber 2026-04-27 19:31:59 +01:00
parent 4d44e7045c
commit 3c38333dd1
2 changed files with 16 additions and 5 deletions

View file

@ -69,10 +69,12 @@ export default defineEventHandler(async (event) => {
// Opportunistic backfill: members predating the helcimCustomerCode field
// get it filled in here so the daily cron acts as the migration. Only on
// the missing path — no overwrite, no extra API call once populated.
if (!member.helcimCustomerCode) {
let customerCode = member.helcimCustomerCode
if (!customerCode) {
try {
const customer = await getHelcimCustomer(member.helcimCustomerId)
if (customer?.customerCode) {
customerCode = customer.customerCode
await Member.findByIdAndUpdate(
member._id,
{ $set: { helcimCustomerCode: customer.customerCode } },
@ -85,9 +87,14 @@ export default defineEventHandler(async (event) => {
}
}
if (!customerCode) {
console.warn(`[reconcile] no customerCode for member=${member._id}; skipping`)
return { error: false, txExamined: 0, created: 0, existed: 0, skipped: 0 }
}
let txs
try {
txs = await listTransactionsWithRetry(member.helcimCustomerId)
txs = await listTransactionsWithRetry(customerCode)
} catch (err) {
console.error(`[reconcile] member=${member._id}: ${err?.message || err}`)
return { error: true }