Skip to content

feat: Rollback fix with suggestion updates#1288

Open
anshulk-public wants to merge 10 commits intomainfrom
rollback_fix_with_suggestion_updates
Open

feat: Rollback fix with suggestion updates#1288
anshulk-public wants to merge 10 commits intomainfrom
rollback_fix_with_suggestion_updates

Conversation

@anshulk-public
Copy link

@anshulk-public anshulk-public commented Jan 27, 2026

Add atomic rollback operation for fixes with suggestion updates

Summary

Adds a new rollbackFixWithSuggestionUpdates() method to FixEntityCollection that atomically rolls back a fix entity and updates all associated suggestions in a single DynamoDB transaction. The method is designed to be generic and reusable, fetching suggestions internally and allowing configurable status updates.

jira

What Changed

  • Added rollbackFixWithSuggestionUpdates() method to FixEntityCollection (lines 283-399)
  • Added TypeScript type definition for the new method in fix-entity/index.d.ts
  • Added comprehensive unit and integration tests covering all validation, transaction scenarios, and edge cases

Why This Change?

This method enables safe, atomic rollback of fixes by:

  1. Marking a FixEntity status to ROLLED_BACK
  2. Marking all associated Suggestion entities to a configurable status (defaults to SKIPPED)

The atomic transaction ensures either all updates succeed or none are applied, preventing partial rollback states that could leave the system in an inconsistent state.

How It Works

The method uses ElectroDB's transaction.write() to perform the following atomically:

  • Fetches all suggestions for the fix entity using the facade layer (getSuggestionsByFixEntityId())
  • Updates the fix entity status to ROLLED_BACK (no status precondition - generic update)
  • Updates all suggestions to the provided newSuggestionStatus (no status precondition - generic update)
  • Extracts suggestion rank values upfront (required for GSI composite key updates)
  • Fetches updated entities after transaction completion
  • Returns model instances for easy consumption by controllers
  • Provides detailed error reporting if the transaction is canceled

Documentation for transact.write()

API Signature

async rollbackFixWithSuggestionUpdates(
fixEntityId: string,
opportunityId: string,
newSuggestionStatus?: string,
options?: {token?: string}
): Promise<{
canceled: boolean,
fix: FixEntity,
suggestions: Array
}>

Validation & Error Handling

  • ✅ All IDs must be valid UUIDs
  • ✅ At least one suggestion update is required
  • ✅ Transaction enforces status preconditions via DynamoDB conditional expressions
  • ✅ Detailed error messages on transaction cancellation
  • ✅ Throws ValidationError for input validation failures
  • ✅ Throws DataAccessError for transaction failures

Version Impact

This is a minor version feature addition (backward compatible).

Please ensure your pull request adheres to the following guidelines:

  • make sure to link the related issues in this description
  • when merging / squashing, make sure the fixed issue references are visible in the commits, for easy compilation of release notes

Related Issues

Thanks for contributing!

@github-actions
Copy link

This PR will trigger a minor release when merged.

@anshulk-public anshulk-public changed the title Rollback fix with suggestion updates feat: Rollback fix with suggestion updates Jan 27, 2026
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

Comments