Skip to content

fix: add mandatory field validation for question and answer in createFlashcard (#1198) - #1529

Open
suhaniiz wants to merge 1 commit into
Canopus-Labs:mainfrom
suhaniiz:fix/flashcard-validation-1198
Open

fix: add mandatory field validation for question and answer in createFlashcard (#1198)#1529
suhaniiz wants to merge 1 commit into
Canopus-Labs:mainfrom
suhaniiz:fix/flashcard-validation-1198

Conversation

@suhaniiz

@suhaniiz suhaniiz commented Aug 7, 2026

Copy link
Copy Markdown
Contributor

📝 Pull Request Description

Related Issue

Closes #1198

Summary

Added early payload validation in createFlashcard to check for missing, empty, or non-string question and answer fields before processing. Previously, invalid or whitespace-only inputs bypassed controller checks and led to unhandled Mongoose schema errors or malformed entries. The endpoint now returns an explicit 400 Bad Request and sanitizes valid inputs using .trim().


Type of Change

  • 🐛 Bug fix (non-breaking change which fixes an issue)
  • ✨ New feature
  • ♻️ Refactoring
  • 📝 Documentation update
  • 🎨 UI/UX improvement
  • 🔥 Other(please describe) ______

How Has This Been Tested?

Describe the testing steps performed.

  • Sent POST /api/flashcards with an empty body {} and verified a 400 Bad Request response.
  • Sent payloads with whitespace strings like {"question": " ", "answer": ""} and confirmed a 400 Bad Request response.
  • Sent valid string payloads and verified 201 Created with trimmed input fields.

Screenshots (if applicable)

N/A


Checklist

  • My code follows the project's guidelines
  • I have tested my changes
  • I have updated documentation where necessary
  • I have linked the related issue
  • My changes do not introduce new warnings or errors

@coderabbitai

coderabbitai Bot commented Aug 7, 2026

Copy link
Copy Markdown

Warning

Review limit reached

@suhaniiz, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 48 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 43f4535d-7e9e-401f-bfa4-2984fd769cda

📥 Commits

Reviewing files that changed from the base of the PR and between 4ba01aa and 2db631a.

📒 Files selected for processing (1)
  • backend/controllers/flashcardController.js

Comment @coderabbitai help to get the list of available commands.

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.

[Bug]: [VALIDATION] Missing mandatory field checks for question and answer in createFlashcard

1 participant