Linh - Fix FAQ unanswered question API false 500 and duplicate detection#2083
Open
linh2020 wants to merge 2 commits intodevelopmentfrom
Open
Linh - Fix FAQ unanswered question API false 500 and duplicate detection#2083linh2020 wants to merge 2 commits intodevelopmentfrom
linh2020 wants to merge 2 commits intodevelopmentfrom
Conversation
…licate detection make owner lookup case-insensitive (/^owner$/i) stop returning 500 when no owner email is found (log question still succeeds) validate/normalize input question before save improve duplicate match to be case-insensitive and whitespace-tolerant return clear 409 message: This question has already been logged
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.



Description
This PR fixes POST /api/faqs/log-unanswered returning false 500 errors after a question is logged, and improves duplicate detection reliability.
Related PRS (if any):
This backend PR is related to the frontend PR#4931
Main changes explained:
Fixed owner lookup to be case-insensitive (/^owner$/i) so valid owners are found consistently.
Removed false failure path: logging a question no longer fails when owner emails are missing.
Added question input validation (Question is required for empty input).
Normalized question text before save (trim + collapse extra spaces).
Hardened duplicate detection to be case-insensitive and whitespace-tolerant.
Preserved explicit duplicate response: 409 - This question has already been logged.
How to test:
Checkout this backend branch locally.
Run backend server (yarn install, yarn start or your local backend start command).
Ensure frontend is running and points to this backend.
Submit a new unanswered FAQ question from /faq.
Verify API responds 201 with Question logged successfully.
Submit the same question again (including variations in casing/spacing).
Verify API responds 409 with This question has already been logged.
Confirm no unexpected 500 occurs in this flow.
Screenshots or videos of changes: