Skip to content

fix: use answersDocId instead of testDocId when deleting answer document#1867

Open
Karrrthik7 wants to merge 1 commit intoruxailab:developfrom
Karrrthik7:bug/remove-user-answer-doc-fix
Open

fix: use answersDocId instead of testDocId when deleting answer document#1867
Karrrthik7 wants to merge 1 commit intoruxailab:developfrom
Karrrthik7:bug/remove-user-answer-doc-fix

Conversation

@Karrrthik7
Copy link

Fixes #1861

Problem

The removeUserAnswer method in AnswerController was deleting the wrong Firestore document.
The code previously used:
userToUpdate.myAnswers[payload.testDocId].testDocId

However, testDocId represents the study identifier, not the Firestore document ID of the answer.
The UserAnswer model stores two fields:

  • testDocId → study identifier
  • answersDocId → Firestore document ID in the answers collection

Because of this mismatch, the system attempted to delete: answers/{testDocId}
instead of the actual answer document: answers/{answersDocId}
This left orphaned answer documents in Firestore when a cooperator was removed.

Solution

The deletion now uses answersDocId instead of testDocId:

const answerDocumentId =
  userToUpdate.myAnswers[payload.testDocId].answersDocId

This ensures the correct document in the answers collection is deleted.

Impact

  • Prevents orphaned answer documents in Firestore
  • Ensures cooperator removal cleans up associated answer data correctly
  • Maintains data integrity for analytics and reporting

Files Changed: src/shared/controllers/AnswerController.js

Screenshots

Screenshot 2026-03-12 125218 Screenshot 2026-03-12 125734

@sonarqubecloud
Copy link

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug: removeUserAnswer deletes testDocId instead of answersDocId, leaving orphaned answer documents

1 participant