Skip to content

Commit

Permalink
Removed id from poitype api
Browse files Browse the repository at this point in the history
  • Loading branch information
Liam Boddin committed Sep 14, 2023
1 parent ba6ab60 commit 7583ca0
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 19 deletions.
6 changes: 1 addition & 5 deletions Server/src/routes/poitype.route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,18 +105,14 @@ export class PoiTypeRoute {
private async updateType(req: Request, res: Response): Promise<void> {
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)
return
}
const userData = userDataPayload.data

if (userData.id !== typeId) {
res.sendStatus(400)
return
}

await database.pois.updateType(typeId, {
name: userData.name,
Expand Down
27 changes: 13 additions & 14 deletions Website/src/app/management/poiTypes/client.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 (
<ManagementForm<CreatePOIType & { id?: number }>
<ManagementForm<CreatePOIType>
mutate_fkt={mutate}
{...{
delete_url,
Expand Down

0 comments on commit 7583ca0

Please sign in to comment.