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;