Add ET member deletion endpoint

This commit is contained in:
regalijan 2023-10-19 16:50:32 -04:00
parent 8ada65b68d
commit 6dc26e40a1
Signed by: regalijan
GPG Key ID: 5D4196DA269EF520

View File

@ -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) { export async function onRequestPost(context: RequestContext) {
const { id, name } = context.data.body; const { id, name } = context.data.body;