Skip to content

Linh - Fix FAQ unanswered question API false 500 and duplicate detection#2083

Open
linh2020 wants to merge 2 commits intodevelopmentfrom
linh_backend_fix_faq_log_question_error
Open

Linh - Fix FAQ unanswered question API false 500 and duplicate detection#2083
linh2020 wants to merge 2 commits intodevelopmentfrom
linh_backend_fix_faq_log_question_error

Conversation

@linh2020
Copy link
Contributor

@linh2020 linh2020 commented Mar 3, 2026

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:

2026-03-02 22_05_28-Greenshot 2026-03-02 22_05_56-Greenshot 2026-03-02 22_06_26-Greenshot

…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
@sonarqubecloud
Copy link

sonarqubecloud bot commented Mar 3, 2026

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.

1 participant