Add clearvisits API endpoint and implement DELETE method***

***Handle error when no id is found in DELETE method***
***Update deleteData function in log page to use clearvisits API endpoint
This commit is contained in:
Sean Morley
2024-04-10 17:54:19 +00:00
parent bc0e1b4db2
commit 3dcad53004
3 changed files with 53 additions and 3 deletions

View File

@@ -0,0 +1,27 @@
import type { RequestEvent } from "@sveltejs/kit";
import { db } from "$lib/db/db.server";
import { eq } from "drizzle-orm";
import { userVisitedAdventures } from "$lib/db/schema";
export async function DELETE(event: RequestEvent): Promise<Response> {
if (!event.locals.user) {
return new Response(JSON.stringify({ error: "No user found" }), {
status: 401,
headers: {
"Content-Type": "application/json",
},
});
}
let res = await db
.delete(userVisitedAdventures)
.where(
eq(userVisitedAdventures.userId, event.locals.user.id),
)
.execute();
return new Response(JSON.stringify({ res: res }), {
status: 200,
headers: {
"Content-Type": "application/json",
},
});
}