You are given an existing backend service for online reviews. The service already supports adding a review and editing an existing review. Successful review creation currently returns HTTP 201, and successful review editing returns the service's normal success status.
The codebase also contains a content-checking utility that can parse a user comment and detect prohibited or sensitive words. Extend both the add-review and edit-review flows so that moderation is enforced consistently.
Requirements:
-
When a user adds or edits a review, check the review text using the existing content-checking utility.
-
If the review contains prohibited content, block the request and return HTTP
403
instead of creating or updating the review.
-
Each prohibited submission increments the user's
violationCount
by
1
.
-
After incrementing the violation count, persist the user record with
await user.save()
or the equivalent persistence call used by the codebase.
-
If
violationCount
becomes greater than
3
, set
user.isFlagged = true
and persist that change.
-
If
user.isFlagged
is already true, the user must remain blocked even when the new review text is clean.
-
Whenever prohibited words are detected, update the user's stored list of violated content words so that it reflects the detected words expected by the unit tests.
-
Apply the same moderation behavior to both add-review and edit-review paths.
The unit tests verify status codes, violation count updates, flagged-user behavior, persistence, and the saved prohibited-word list.