Make note creation
This commit is contained in:
8
functions/api/game-bans/notes/_middleware.ts
Normal file
8
functions/api/game-bans/notes/_middleware.ts
Normal 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();
|
||||
}
|
||||
23
functions/api/game-bans/notes/create.ts
Normal file
23
functions/api/game-bans/notes/create.ts
Normal 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();
|
||||
}
|
||||
Reference in New Issue
Block a user