Skip to content

OUT-3523: restore account refs instead of clearing them when QB account is missing#212

Merged
SandipBajracharya merged 4 commits intomasterfrom
OUT-3523
Apr 3, 2026
Merged

OUT-3523: restore account refs instead of clearing them when QB account is missing#212
SandipBajracharya merged 4 commits intomasterfrom
OUT-3523

Conversation

@SandipBajracharya
Copy link
Copy Markdown
Collaborator

@SandipBajracharya SandipBajracharya commented Apr 3, 2026

Summary

checkAndUpdateAccountStatus previously called removeAccountMapping which set
incomeAccountRef/expenseAccountRef/assetAccountRef to empty string in the DB
when a QB account was not found. Only the auth (re-auth) flow had fallback
logic to recreate these — webhook callers (product, invoice, payment, sync)
permanently lost the values, causing invoice sync failures.

Changes

  • Move manage{Income,Expense,Asset}AccountRef from AuthService to TokenService
  • Replace removeAccountMapping with updateAccountMapping that persists the restored ref
  • Add restoreAccountRef dispatcher to find-or-create the correct QB account
  • checkAndUpdateAccountStatus now restores (not clears) when account is missing or accountId is empty
  • Remove redundant fallback checks in AuthService#handleAccountReferences

Testing Criteria

https://www.loom.com/share/167e02950dfe4db09c1b17597f4d3131

SandipBajracharya and others added 2 commits April 3, 2026 12:21
…account is missing

checkAndUpdateAccountStatus previously called removeAccountMapping which set
incomeAccountRef/expenseAccountRef/assetAccountRef to empty string in the DB
when a QB account was not found. Only the auth (re-auth) flow had fallback
logic to recreate these — webhook callers (product, invoice, payment, sync)
permanently lost the values, causing invoice sync failures.

Changes:
- [x] Move manage{Income,Expense,Asset}AccountRef from AuthService to TokenService
- [x] Replace removeAccountMapping with updateAccountMapping that persists the restored ref
- [x] Add restoreAccountRef dispatcher to find-or-create the correct QB account
- [x] checkAndUpdateAccountStatus now restores (not clears) when account is missing or accountId is empty
- [x] Remove redundant fallback checks in AuthService#handleAccountReferences
- [x] Verify clean TypeScript compilation (tsc --noEmit)

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
- Make manage{Income,Expense,Asset}AccountRef private in TokenService
- Add optional chaining on .Id access for safe null/undefined handling
- Split comma-chained const declarations into separate statements
- Restore doc comments on manageAssetAccountRef

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@linear
Copy link
Copy Markdown

linear bot commented Apr 3, 2026

@vercel
Copy link
Copy Markdown

vercel bot commented Apr 3, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
quickbooks-sync Ready Ready Preview, Comment Apr 3, 2026 7:29am
quickbooks-sync (dev) Ready Ready Preview, Comment Apr 3, 2026 7:29am

Request Review

Rename methods to better reflect their find-or-create semantics and add
consistent logging across all three account ref methods.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
…fety

- Type payload as QBPortalConnectionUpdateSchemaType for compile-time safety
- Log error when updateAccountMapping matches no DB row
- Add null guard after createAccount in all getOrCreate*AccountRef methods
- Add explicit Promise<string> return type on checkAndUpdateAccountStatus
- Log restored account ref ID after restoration for debugging
- Fix "vaalue" typo in auth.service.ts

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Copy link
Copy Markdown
Collaborator

@priosshrsth priosshrsth left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm.

@SandipBajracharya SandipBajracharya merged commit da03e90 into master Apr 3, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants