added base examples and drills
This commit is contained in:
@@ -0,0 +1,3 @@
|
||||
# moderation original
|
||||
|
||||
Messy moderation logic mixing policy rules, time, logging, mutation, and file I/O.
|
||||
@@ -0,0 +1,30 @@
|
||||
const fs = require("fs");
|
||||
|
||||
function reviewPost(filePath, postId) {
|
||||
const raw = fs.readFileSync(filePath, "utf8");
|
||||
const state = JSON.parse(raw);
|
||||
const post = state.posts.find((item) => item.id === postId);
|
||||
|
||||
if (!post) {
|
||||
throw new Error("Post not found");
|
||||
}
|
||||
|
||||
let action = "approve";
|
||||
|
||||
if (post.text.includes("buy now") || post.text.includes("free money")) {
|
||||
action = "reject";
|
||||
}
|
||||
|
||||
if (post.reports > 3) {
|
||||
action = "escalate";
|
||||
}
|
||||
|
||||
post.status = action;
|
||||
post.reviewedAt = new Date().toISOString();
|
||||
fs.writeFileSync(filePath, JSON.stringify(state, null, 2));
|
||||
console.log("Moderation action", postId, action);
|
||||
|
||||
return { action };
|
||||
}
|
||||
|
||||
module.exports = { reviewPost };
|
||||
@@ -0,0 +1,11 @@
|
||||
{
|
||||
"posts": [
|
||||
{
|
||||
"id": "post-1",
|
||||
"text": "free money if you buy now",
|
||||
"reports": 1,
|
||||
"status": "pending",
|
||||
"reviewedAt": null
|
||||
}
|
||||
]
|
||||
}
|
||||
Reference in New Issue
Block a user