Refactor data fields in dashboard page

This commit is contained in:
Nils 2024-01-16 14:19:14 +01:00
parent 11051d85e6
commit 8d6c74f5e5
2 changed files with 33 additions and 5 deletions

View File

@ -58,7 +58,7 @@ export default function Page() {
]; ];
const rows = [ 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 ( return (
@ -106,6 +106,7 @@ export default function Page() {
sx={{ sx={{
marginTop: "1rem", marginTop: "1rem",
borderRadius: "20px", borderRadius: "20px",
width: "auto",
}} }}
initialState={{ initialState={{
pagination: { pagination: {

View File

@ -1,12 +1,39 @@
import type { NextApiRequest, NextApiResponse } from 'next' import type { NextApiRequest, NextApiResponse } from 'next'
import { PrismaClient } from '@prisma/client'
const prisma = new PrismaClient()
type ResponseData = { type ResponseData = {
message: string vorname: string
nachname: string
geburtsdatum: string
anstellungsdatum: string
} }
export default function handler( export default async function handler(
req: NextApiRequest, req: NextApiRequest,
res: NextApiResponse<ResponseData> res: NextApiResponse<ResponseData>
) { ) {
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 });
} }