From ac56a62a5dfd72c743bda935418706e7652904b9 Mon Sep 17 00:00:00 2001 From: regalijan Date: Thu, 19 Oct 2023 16:51:14 -0400 Subject: [PATCH] Retrieve self-submitted appeals endpoint --- functions/api/me/appeals.ts | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 functions/api/me/appeals.ts diff --git a/functions/api/me/appeals.ts b/functions/api/me/appeals.ts new file mode 100644 index 0000000..944bcbf --- /dev/null +++ b/functions/api/me/appeals.ts @@ -0,0 +1,13 @@ +import { jsonError, jsonResponse } from "../../common.js"; + +export async function onRequestGet(context: RequestContext) { + const { results, success } = await context.env.D1.prepare( + "SELECT approved, created_at, open FROM appeals WHERE user = ?;", + ) + .bind(context.data.current_user.id) + .all(); + + if (!success) return jsonError("Unable to retrieve appeals", 500); + + return jsonResponse(JSON.stringify(results)); +}