fix(reconcile): pass customerCode (not helcimCustomerId) to Helcim transactions API
This commit is contained in:
parent
4d44e7045c
commit
3c38333dd1
2 changed files with 16 additions and 5 deletions
|
|
@ -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 }
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue