Greatly reduce repeated code

This commit is contained in:
2023-10-19 16:50:48 -04:00
parent 47e639be43
commit dd2d9f2672
34 changed files with 196 additions and 481 deletions

View File

@ -1,13 +1,9 @@
import { jsonError } from "../../common.js";
export async function onRequestPost(context: RequestContext) {
const { id } = context.data.body;
if (!id)
return new Response('{"error":"No ID provided"}', {
headers: {
"content-type": "application/json",
},
status: 400,
});
if (!id) return jsonError("No ID provided", 400);
const reportUserId = await context.env.DATA.get(`reportprocessing_${id}`);
@ -16,12 +12,7 @@ export async function onRequestPost(context: RequestContext) {
(context.data.current_user?.id !== reportUserId &&
context.request.headers.get("CF-Connecting-IP") !== reportUserId)
)
return new Response('{"error":"No processing report with that ID found"}', {
headers: {
"content-type": "application/json",
},
status: 404,
});
return jsonError("No processing report with that ID found", 404);
await context.env.DATA.delete(`report_${id}`);