added base examples and drills

This commit is contained in:
2026-05-20 17:42:01 -06:00
parent 9bf788d9ef
commit 4fc0d851e7
40 changed files with 802 additions and 1 deletions
+3
View File
@@ -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 };
+11
View File
@@ -0,0 +1,11 @@
{
"posts": [
{
"id": "post-1",
"text": "free money if you buy now",
"reports": 1,
"status": "pending",
"reviewedAt": null
}
]
}