Skip to content

feat: Rollback fix with suggestion updates#1288

Closed
anshulk-public wants to merge 13 commits intomainfrom
rollback_fix_with_suggestion_updates
Closed

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

Conversation

@anshulk-public
Copy link
Copy Markdown
Contributor

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

Add atomic update for fix entity and suggestion statuses

Summary

Adds updateFixAndSuggestionsStatus() to FixEntityCollection that atomically updates a fix entity’s status and all linked suggestions’ status in a single database operation. The method uses a PostgREST RPC so all updates succeed or fail together in one transaction. It is generic and reusable, with configurable fix and suggestion statuses (e.g. rollback: fix → ROLLED_BACK, suggestions → SKIPPED).

Jira

What changed

  • Implemented updateFixAndSuggestionsStatus() on FixEntityCollection.
  • Uses PostgREST RPC rpc_update_fix_and_suggestions_status (migration in mysticat-data-service)
  • Updated TypeScript definition in fix-entity/index.d.ts (signature and return type)
  • Return type is { fix, suggestions }
  • Updated unit tests for the RPC-based flow (validation, RPC call shape, errors, post-RPC fetch)
  • Updated api-service rollback controller and tests to use the new return shape

Why this change?

  • Atomicity: Either the fix and all linked suggestions are updated, or none are. No partial rollback.
  • Single round-trip: One RPC call instead of multiple PATCHes, with transaction semantics handled in the database.
  • Reusable: Same method supports rollback (e.g. ROLLED_BACK / SKIPPED) and other status flows via parameters.
  • Backend alignment: Logic lives in PostgreSQL (mysticat-data-service RPC) instead of application-level transaction orchestration.

How it works

  1. Validate: fixEntityId and opportunityId (UUIDs), newSuggestionStatus and newFixEntityStatus (non-empty strings).
  2. Pre-check: Load suggestions via getSuggestionsByFixEntityId(fixEntityId). If none, throw ValidationError('No suggestions found for the fix entity').
  3. RPC: Call postgrestService.rpc('rpc_update_fix_and_suggestions_status', { p_fix_entity_id, p_fix_entity_status, p_new_suggestion_status }). The DB function updates fix_entities and all linked rows in suggestions in one transaction.
  4. On RPC error: Throw DataAccessError with the RPC error message (or a generic message if none).
  5. Post-update: Fetch updated fix and suggestions with findById(fixEntityId) and getSuggestionsByFixEntityId(fixEntityId). If fix is missing, throw DataAccessError.
  6. Return: { fix, suggestions } (model instances) for use by controllers.

API signature

updateFixAndSuggestionsStatus(
  fixEntityId: string,
  opportunityId: string,
  newSuggestionStatus?: string,   // default: 'SKIPPED'
  newFixEntityStatus?: string,   // default: 'ROLLED_BACK'
  options?: object               // reserved
): Promise<{ fix: FixEntity, suggestions: Array<Suggestion> }>


## 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
Copy Markdown

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
@anshulk-public anshulk-public force-pushed the rollback_fix_with_suggestion_updates branch from 0e55901 to 5450020 Compare February 25, 2026 18:54
@anshulk-public
Copy link
Copy Markdown
Contributor Author

anshulk-public commented Feb 27, 2026

@ekremney @solaris007
Can you please review this PR??
As it contains transact.write() which is part of electroDB.

@solaris007
Copy link
Copy Markdown
Member

solaris007 commented Feb 27, 2026

@anshulk-public @sandsinh I am not sure it will have a big impact, as we are in the process of migrating to the new data service under PostgREST.

@anshulk-public anshulk-public force-pushed the rollback_fix_with_suggestion_updates branch from c865909 to a6ecac6 Compare March 12, 2026 10:15
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.

3 participants