Skip to content

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

@Karrrthik7

Description

@Karrrthik7

The cooperator removal flow deletes the wrong Firestore document from the answers collection.

In AnswerController.js, the code uses:

const answerDocumentId =
  userToUpdate.myAnswers[`${payload.testDocId}`].testDocId
await super.delete(COLLECTION, answerDocumentId)

testDocId is the study ID, not the answer document ID. The UserAnswer model stores both testDocId and answersDocId, so the delete operation should use answersDocId.

Steps to Reproduce

  1. Create a study with an answersDocId.
  2. Add a cooperator so user.myAnswers[testDocId] contains both fields.
  3. Remove the cooperator.
  4. Check Firestore the real answer document still exists.

Expected Behavior

Deleting a cooperator should remove the correct document using answersDocId.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions