Skip to content

fix: resolve quiz score calculation and MongoDB validation errors - #40

Merged
BruArtist merged 1 commit into
mainfrom
fix/score-calculation
Apr 11, 2026
Merged

BruArtist merged 1 commit into
mainfrom
fix/score-calculation

Conversation

@nasseralkawari

Copy link
Copy Markdown
Collaborator

This PR fixes backend issues related to quiz submission, score calculation, and MongoDB validation errors.

Problem

Submitting a quiz resulted in the following error:

Failed to calculate score
Result validation failed: wrongAnswers and correctAnswers are required

Root Cause

  • calculateScore did not return required fields (correctAnswers, wrongAnswers)
  • /submit route passed incomplete data to MongoDB
  • Result model validation failed due to missing fields

Fix Implemented

  • Updated calculateScore to return:

    • score
    • total
    • correctAnswers
    • wrongAnswers
  • Updated /submit route to:

    • validate input properly
    • normalize result data
    • include all required fields before saving
  • ensured answers are stored correctly

Testing

  • Generated quiz from frontend

  • Answered all questions

  • Submitted successfully

  • Verified:

    • score is calculated correctly
    • result is saved in MongoDB
    • no validation errors

Impact

  • Fixes critical backend bug blocking quiz submission
  • Enables full quiz flow (Generate → Answer → Submit → Feedback → Dashboard)

Notes

  • Improves data consistency between frontend and backend
  • Ensures MongoDB schema validation passes correctly

@BruArtist
BruArtist merged commit 79ec862 into main Apr 11, 2026
1 check passed
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