diff --git a/src/app/dashboard/page.tsx b/src/app/dashboard/page.tsx index c73a157..6fc22b5 100644 --- a/src/app/dashboard/page.tsx +++ b/src/app/dashboard/page.tsx @@ -58,7 +58,7 @@ export default function Page() { ]; const rows = [ - { id: "1", Vorname:data.message, Nachname: "test", Anstelldatum: "test", Geburtstag: "test" } + { id: "1", Vorname:data.vorname, Nachname: data.nachname, Anstelldatum: data.anstellungsdatum, Geburtstag: data.geburtsdatum } ]; return ( @@ -106,6 +106,7 @@ export default function Page() { sx={{ marginTop: "1rem", borderRadius: "20px", + width: "auto", }} initialState={{ pagination: { diff --git a/src/pages/api/hello.ts b/src/pages/api/hello.ts index 5be9403..085f79a 100644 --- a/src/pages/api/hello.ts +++ b/src/pages/api/hello.ts @@ -1,12 +1,39 @@ import type { NextApiRequest, NextApiResponse } from 'next' +import { PrismaClient } from '@prisma/client' +const prisma = new PrismaClient() + type ResponseData = { - message: string + vorname: string + nachname: string + geburtsdatum: string + anstellungsdatum: string + } - -export default function handler( + +export default async function handler( req: NextApiRequest, res: NextApiResponse ) { - res.status(200).send({ message: 'Ingrid' }) + const result = await prisma.mitarbeiter.findFirst({ + select: { Vorname: true }, + orderBy: { ID: 'asc' }, + }); + const result2 = await prisma.mitarbeiter.findFirst({ + select: { Nachname: true }, + orderBy: { ID: 'asc' }, + }); + const result3 = await prisma.mitarbeiter.findFirst({ + select: { Geburtstag: true }, + orderBy: { ID: 'asc' }, + }); + const result4 = await prisma.mitarbeiter.findFirst({ + select: { Anstelldatum: true }, + orderBy: { ID: 'asc' }, + }); + const firstname = result?.Vorname ?? ''; + const lastname = result2?.Nachname ?? ''; + const birthday = result3?.Geburtstag ?? ''; + const hiredate = result4?.Anstelldatum ?? ''; + res.status(200).send({ vorname: firstname, nachname: lastname, geburtsdatum: birthday as string, anstellungsdatum: hiredate as string }); }