Skip to content

[_]: fix(account): implement rollback functionality for account and address deletions#84

Merged
jzunigax2 merged 1 commit into
masterfrom
fix/force-delete-on-rollback
Jul 7, 2026
Merged

[_]: fix(account): implement rollback functionality for account and address deletions#84
jzunigax2 merged 1 commit into
masterfrom
fix/force-delete-on-rollback

Conversation

@jzunigax2

@jzunigax2 jzunigax2 commented Jul 7, 2026

Copy link
Copy Markdown
Contributor
  • Added rollbackAccount and rollbackAddress helper methods to handle deletions with a force option.
  • Updated existing deletion calls in AccountService to utilize the new rollback methods.
  • Enhanced unit tests to verify the correct behavior of account and address rollbacks during error scenarios.

Summary by CodeRabbit

  • Bug Fixes
    • Improved cleanup behavior when account or address setup fails, reducing the chance of leftover partial records.
    • Failure handling is now more consistent across rollback paths, including cases where external provisioning also fails.
    • Updated deletion behavior to fully remove records during rollback when needed.

…s deletions

- Added `rollbackAccount` and `rollbackAddress` helper methods to handle deletions with a force option.
- Updated existing deletion calls in `AccountService` to utilize the new rollback methods.
- Enhanced unit tests to verify the correct behavior of account and address rollbacks during error scenarios.
@coderabbitai

coderabbitai Bot commented Jul 7, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: a05794d7-e606-438a-a9c4-f1c1c703c456

📥 Commits

Reviewing files that changed from the base of the PR and between c5ed582 and 031809f.

📒 Files selected for processing (4)
  • src/modules/account/account.service.spec.ts
  • src/modules/account/account.service.ts
  • src/modules/account/repositories/account.repository.ts
  • src/modules/account/repositories/address.repository.ts

📝 Walkthrough

Walkthrough

This PR changes account and address deletion during rollback scenarios in AccountService to hard-delete records via a new force option added to AccountRepository.delete and AddressRepository.delete. Rollback logic is centralized into new private helpers (rollbackAccount, rollbackAddress, tryDeleteProviderAccount), and corresponding tests are updated to assert the new hard-delete behavior.

Changes

Rollback and force-delete cohort

Layer / File(s) Summary
Repository delete signature accepts force option
src/modules/account/repositories/account.repository.ts, src/modules/account/repositories/address.repository.ts
delete(id, options?: { force?: boolean }) forwards options?.force to Sequelize destroy calls, replacing the always-soft-delete behavior.
Centralized rollback helpers
src/modules/account/account.service.ts
New private helpers rollbackAccount, rollbackAddress, and tryDeleteProviderAccount perform best-effort provider deletion (warns on failure) followed by force-deleting local records.
provisionAccount rollback wiring
src/modules/account/account.service.ts
Failure handlers in provisionAccount call rollbackAccount(account.id) or rollbackAccount(account.id, created.externalId) instead of directly invoking accounts.delete.
addAddress rollback wiring
src/modules/account/account.service.ts
Failure handlers in addAddress call rollbackAddress(newAddressId) or rollbackAddress(newAddressId, created.externalId), consolidating the previous two-stage cleanup try/catch blocks.
Test updates for force-delete assertions
src/modules/account/account.service.spec.ts
Tests for provisionAccount and addAddress rollback scenarios now assert delete(id, { force: true }) calls and adjust related expectations.

Estimated code review effort: 3 (Moderate) | ~25 minutes

Sequence Diagram(s)

sequenceDiagram
  participant Caller
  participant AccountService
  participant Provider
  participant AccountRepository
  Caller->>AccountService: provisionAccount()
  AccountService->>Provider: createAccount()
  Provider-->>AccountService: success (externalId)
  AccountService->>Provider: createProviderLink() / createNetworkBucket()
  Provider-->>AccountService: error
  AccountService->>AccountService: rollbackAccount(account.id, externalId)
  AccountService->>Provider: tryDeleteProviderAccount(externalId)
  Provider-->>AccountService: warn on failure (ignored)
  AccountService->>AccountRepository: delete(account.id, { force: true })
Loading

Sequence: Poem

A rabbit hops through rollback code,
Force-deleting down the failure road.
Accounts and addresses, cleaned up tight,
No orphaned rows left in the night.
Helpers centralize what once was strewn —
Hard deletes now, gone by noon! 🐰🗑️

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly matches the main change: adding rollback handling for account and address deletions.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/force-delete-on-rollback

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@sonarqubecloud

sonarqubecloud Bot commented Jul 7, 2026

Copy link
Copy Markdown

@jzunigax2 jzunigax2 marked this pull request as ready for review July 7, 2026 13:08
@jzunigax2 jzunigax2 requested a review from xabg2 July 7, 2026 13:08
@jzunigax2 jzunigax2 self-assigned this Jul 7, 2026
@jzunigax2 jzunigax2 added the bug Something isn't working label Jul 7, 2026
@jzunigax2 jzunigax2 merged commit 1e57acc into master Jul 7, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants