← 返回 amazon 的题目列表Online Review Content Moderation
类型:online_judge
Problem: Online Review Content Moderation
You are maintaining an online review system. The project already contains user, review, and content-moderation related code. Complete the moderation logic in both the add review and edit review flows so that the unit tests pass.
A helper function already exists to check whether review content contains bad or sensitive words. It may also return the matched bad words.
When a user adds or edits a review, the following rules must be enforced:
If the user is already marked as isFlagged = true, the request must be blocked regardless of whether the new content is clean.
Both add-review and edit-review requests must check the review content for violations.
If the review contains bad content:
Return HTTP 403, instead of success status such as 201 or 200.
Increment the user's violationCount by 1.
Save the matched bad words into the user's violatedWords / violatedContentWords field.
After updating user fields, call and await user.save().
If the user's violation count becomes greater than 3, set user.isFlagged = true and save it.
If the content is clean and the user is not flagged, continue with the original add/edit review flow.
What to Implement
Modify the existing addReview and editReview handlers so that they correctly call the content-checking helper and update:
HTTP status code
violationCount
isFlagged
matched violated words
user persistence logic
Assumed Data Structure
user = {
id: string,
violationCount: number,
isFlagged: boolean,
violatedWords: string[],
save: async function()
}
The content checker may look like:
checkContent(content) -> {
isViolation: boolean,
words: string[]
}
Example
If a user submits:
"This product is scam"
and scam is a bad word, return:
HTTP 403
and update:
user.violationCount += 1
user.violatedWords includes "scam"
Example
Input
User: { violationCount: 0, isFlagged: false, violatedWords: [] }
Action: POST /reviews
Content: "Great product"
Bad words: ["scam", "fake"]
Output
HTTP 201
User: { violationCount: 0, isFlagged: false, violatedWords: [] }
Review is created