From d100a227a4bcae2b728ffe6a17dd0a6b97e683e9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafa=C5=82=20Weso=C5=82owski?= Date: Fri, 14 Jun 2024 16:44:55 +0200 Subject: [PATCH] build fail fix --- src/pages/api/user/[id].ts | 63 -------------------------------------- 1 file changed, 63 deletions(-) delete mode 100644 src/pages/api/user/[id].ts diff --git a/src/pages/api/user/[id].ts b/src/pages/api/user/[id].ts deleted file mode 100644 index 5f416f8..0000000 --- a/src/pages/api/user/[id].ts +++ /dev/null @@ -1,63 +0,0 @@ -import type { APIRoute } from "astro"; -import {deleteUser, updateUser} from "../../../lib/user.ts"; - -export const POST: APIRoute = async ({ params, redirect, request }) => { - const formData = await request.formData(); - - const email = formData.get("email")?.toString(); - const password = formData.get("password")?.toString(); - const checkPw = formData.get("checkPw")?.toString(); - - let missingFields = []; - - if (!email) missingFields.push("email"); - - if (missingFields.length > 0) { - throw new Response(`Missing required fields: ${missingFields.join(', ')}`, { - status: 400, - }); - } - - if (!params.id) { - return new Response("Cannot find service", { - status: 404, - }); - } - - try { - if (password && checkPw) { - await updateUser({ - id: params.id as unknown as number, - email: email, - password: password, - }) - } else { - await updateUser({ - id: params.id as unknown as number, - email: email, - }) - } - } catch (error) { - return new Response("Something went wrong", { - status: 500, - }); - } - return redirect("/admin/user"); -}; - -export const DELETE: APIRoute = async ({ params, redirect }) => { - if (!params.id) { - return new Response("Cannot find user", { - status: 404, - }); - } - - try { - await deleteUser(params.id as unknown as number); - } catch (error) { - return new Response("Something went wrong", { - status: 500, - }); - } - return redirect("/admin/user"); -};