From fa0b9049ef6aa3822b2ed9c3526d8513a02dc6ac Mon Sep 17 00:00:00 2001 From: Dobromir Popov Date: Sun, 28 Apr 2024 14:02:57 +0300 Subject: [PATCH] add accepted cover requests --- pages/api/data/prisma/[...model].ts | 3 +++ pages/cart/reports/coverMe.tsx | 31 +++++++++-------------------- 2 files changed, 12 insertions(+), 22 deletions(-) diff --git a/pages/api/data/prisma/[...model].ts b/pages/api/data/prisma/[...model].ts index fb60ee3..97c1687 100644 --- a/pages/api/data/prisma/[...model].ts +++ b/pages/api/data/prisma/[...model].ts @@ -35,6 +35,9 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse) throw new Error('Model is required as a part of the URL path.'); } const modelName = modelArray[0]; // Get the first part of the model array + if (!prisma[modelName]) { + throw new Error(`Model ${modelName} not found in Prisma client.`); + } const result = await prisma[modelName].findMany(queryOptions); res.status(200).json(result); } catch (error) { diff --git a/pages/cart/reports/coverMe.tsx b/pages/cart/reports/coverMe.tsx index b4c8e97..d2e2971 100644 --- a/pages/cart/reports/coverMe.tsx +++ b/pages/cart/reports/coverMe.tsx @@ -25,26 +25,11 @@ export default function EventLogList() { useEffect(() => { const fetchLocations = async () => { try { - console.log("fetching locations"); - const { data: locData } = await axiosInstance.get("/api/data/locations"); - setLocations(locData); - console.log(locData); - axiosInstance.get(`/api/data/eventlogs`) - .then((res) => { - // let reports = res.data; - // reports.forEach((report) => { - // report.location = data.find((loc) => loc.id === report.locationId); - // }); - setEventLog(res.data); - }) - .catch((err) => { - console.log(err); - }); - - const { data: eventLogsData } = await axiosInstance.get(`/api/data/prisma/eventlog?where={"type":"${EventLogType.AssignmentReplacementAccepted}"}`) + const { data: eventLogsData } = await axiosInstance.get(`/api/data/prisma/eventLog?where={"type":"${EventLogType.AssignmentReplacementAccepted}"} + &include={"publisher":{"select":{"firstName":true,"lastName":true}},"shift":{"include":{"publishers":{"select":{"firstName":true,"lastName":true}}}}}`); setEventLog(eventLogsData); - //get shifts where publicGuid is not null - const { data: shiftsData } = await axiosInstance.get(`/api/data/prisma/assignment?where={"publicGuid":{"not":"null"}}&include={"shift":true,"publisher":{"select":{"firstName":true,"lastName":true}}}`) + + const { data: shiftsData } = await axiosInstance.get(`/api/data/prisma/assignment?where={"publicGuid":{"not":"null"}}&include={"shift":{"include":{"publishers":{"select":{"firstName":true,"lastName":true}}}},"publisher":{"select":{"firstName":true,"lastName":true}}}`) setRequestedAssignments(shiftsData); } catch (error) { @@ -71,7 +56,7 @@ export default function EventLogList() {