From 6dc26e40a10359848f3268554a46f5d3e434c626 Mon Sep 17 00:00:00 2001 From: regalijan Date: Thu, 19 Oct 2023 16:50:32 -0400 Subject: [PATCH] Add ET member deletion endpoint --- .../api/events-team/team-members/user.ts | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/functions/api/events-team/team-members/user.ts b/functions/api/events-team/team-members/user.ts index da3ebb9..865a562 100644 --- a/functions/api/events-team/team-members/user.ts +++ b/functions/api/events-team/team-members/user.ts @@ -1,3 +1,29 @@ +export async function onRequestDelete(context: RequestContext) { + const { id } = context.data.body; + + if ( + typeof id !== "string" || + id.search(/\D/) || + id.length > 19 || + id.length < 17 + ) + return new Response('{"error":"Invalid ID"}', { + headers: { + "content-type": "application/json", + }, + status: 400, + }); + + await context.env.DATA.delete(`etmember_${id}`); + await context.env.D1.prepare("DELETE FROM et_members WHERE id = ?;") + .bind(id) + .run(); + + return new Response(null, { + status: 204, + }); +} + export async function onRequestPost(context: RequestContext) { const { id, name } = context.data.body;