Make note creation

This commit is contained in:
2025-10-13 13:49:30 -04:00
parent b1448ac30e
commit 42f13612b1
2 changed files with 31 additions and 0 deletions

View File

@@ -0,0 +1,8 @@
import { jsonError } from "../../../common.js";
export async function onRequest(context: RequestContext) {
if (!(context.data.current_user?.permissions & (1 << 5)))
return jsonError("Forbidden", 403);
return await context.next();
}

View File

@@ -0,0 +1,23 @@
import { jsonError } from "../../../common.js";
export async function onRequestPost(context: RequestContext) {
const { content, target } = context.data.body;
if (typeof content !== "string")
return jsonError("'content' property is not a string", 400);
if (typeof target !== "number" || !Number.isSafeInteger(target))
return jsonError("'target' property is not a valid number", 400);
if (content.length > 1000)
return jsonError(
"'content' property must be less than 1000 characters",
400,
);
const id = `${Date.now()}${crypto.randomUUID().replaceAll("-", "")}`;
await context.env.D1.prepare(
"INSERT INTO game_mod_notes (content, created_at, created_by, id, target) VALUES (?, ?, ?, ?, ?);",
).bind(content, Date.now(), context.data.current_user.id, id, target).first();
}