From 7583ca075466fb51ffc82b51263d05fcbc492618 Mon Sep 17 00:00:00 2001 From: Liam Boddin Date: Thu, 14 Sep 2023 12:04:36 +0200 Subject: [PATCH] Removed id from poitype api --- Server/src/routes/poitype.route.ts | 6 +---- .../src/app/management/poiTypes/client.tsx | 27 +++++++++---------- 2 files changed, 14 insertions(+), 19 deletions(-) diff --git a/Server/src/routes/poitype.route.ts b/Server/src/routes/poitype.route.ts index c069e0fe..9c1dfc30 100644 --- a/Server/src/routes/poitype.route.ts +++ b/Server/src/routes/poitype.route.ts @@ -105,7 +105,7 @@ export class PoiTypeRoute { private async updateType(req: Request, res: Response): Promise { const typeId: number = parseInt(req.params.typeId) - const userDataPayload = APIPoiType.safeParse(req.body) + const userDataPayload = CreatePOIType.safeParse(req.body) if (!userDataPayload.success) { logger.error(userDataPayload.error) res.sendStatus(400) @@ -113,10 +113,6 @@ export class PoiTypeRoute { } const userData = userDataPayload.data - if (userData.id !== typeId) { - res.sendStatus(400) - return - } await database.pois.updateType(typeId, { name: userData.name, diff --git a/Website/src/app/management/poiTypes/client.tsx b/Website/src/app/management/poiTypes/client.tsx index bacfde26..1a6b91ee 100644 --- a/Website/src/app/management/poiTypes/client.tsx +++ b/Website/src/app/management/poiTypes/client.tsx @@ -5,17 +5,17 @@ This is a co-located client-component. It is not in the components folder, becau else, but also not in ´page.tsx` as we need to obtain the currently selected track id on the server. */ -import { useState } from "react"; -import useSWR from "swr"; -import { Option } from "@/utils/types"; -import { CreatePOIType, POITypeIcon } from "@/utils/api"; -import { Options, SingleValue } from "react-select"; -import IconSelection from "@/app/management/components/iconSelection"; -import { getFetcher } from "@/utils/fetcher"; -import { ErrorMessage } from "@/app/management/components/errorMessage"; -import StyledSelect from "@/app/management/components/styledSelect"; -import { InputWithLabel } from "@/app/management/components/inputWithLabel"; -import ManagementForm from "@/app/management/components/managementForm"; +import { useState } from "react" +import useSWR from "swr" +import { Option } from "@/utils/types" +import { CreatePOIType, POITypeIcon } from "@/utils/api" +import { Options, SingleValue } from "react-select" +import IconSelection from "@/app/management/components/iconSelection" +import { getFetcher } from "@/utils/fetcher" +import { ErrorMessage } from "@/app/management/components/errorMessage" +import StyledSelect from "@/app/management/components/styledSelect" +import { InputWithLabel } from "@/app/management/components/inputWithLabel" +import ManagementForm from "@/app/management/components/managementForm" export default function POITypeManagement({ noFetch = false }: { noFetch?: boolean }) { // fetch Vehicle information with swr. @@ -57,9 +57,8 @@ export default function POITypeManagement({ noFetch = false }: { noFetch?: boole const update_invalid_msg = iconSelected ? undefined : "Bitte wählen Sie ein Icon aus!"; const create_update_url = creating ? `/webapi/poiTypes/create` : `/webapi/poiTypes/update/${selType.value}`; - const create_update_payload: (CreatePOIType & { id?: number }) | undefined = iconSelected + const create_update_payload: CreatePOIType | undefined = iconSelected ? { - id: selType.value === "" ? undefined : selType.value, name: typeName, icon: typeIcon, description: typeDescription || undefined @@ -93,7 +92,7 @@ export default function POITypeManagement({ noFetch = false }: { noFetch?: boole // Note: the onChange event for the inputs is needed as this is a controlled form. Se React documentation return ( - + mutate_fkt={mutate} {...{ delete_url,