Commit 8abd310c authored by Hendrik Garske's avatar Hendrik Garske

Fix: Next.js 16 async params in API routes

parent 4f78567b
Pipeline #4 failed with stages
in 24 seconds
...@@ -3,11 +3,12 @@ import { prisma } from "@/lib/prisma" ...@@ -3,11 +3,12 @@ import { prisma } from "@/lib/prisma"
export async function GET( export async function GET(
request: NextRequest, request: NextRequest,
{ params }: { params: { id: string } } { params }: { params: Promise<{ id: string }> }
) { ) {
try { try {
const { id } = await params
const customer = await prisma.customer.findUnique({ const customer = await prisma.customer.findUnique({
where: { id: params.id }, where: { id },
include: { include: {
timeEntries: { timeEntries: {
include: { include: {
...@@ -33,9 +34,10 @@ export async function GET( ...@@ -33,9 +34,10 @@ export async function GET(
export async function PUT( export async function PUT(
request: NextRequest, request: NextRequest,
{ params }: { params: { id: string } } { params }: { params: Promise<{ id: string }> }
) { ) {
try { try {
const { id } = await params
const body = await request.json() const body = await request.json()
const { name, email, phone, company, address, notes } = body const { name, email, phone, company, address, notes } = body
...@@ -44,7 +46,7 @@ export async function PUT( ...@@ -44,7 +46,7 @@ export async function PUT(
} }
const customer = await prisma.customer.update({ const customer = await prisma.customer.update({
where: { id: params.id }, where: { id },
data: { data: {
name, name,
email: email || null, email: email || null,
...@@ -64,11 +66,12 @@ export async function PUT( ...@@ -64,11 +66,12 @@ export async function PUT(
export async function DELETE( export async function DELETE(
request: NextRequest, request: NextRequest,
{ params }: { params: { id: string } } { params }: { params: Promise<{ id: string }> }
) { ) {
try { try {
const { id } = await params
await prisma.customer.delete({ await prisma.customer.delete({
where: { id: params.id }, where: { id },
}) })
return NextResponse.json({ success: true }) return NextResponse.json({ success: true })
......
...@@ -3,11 +3,12 @@ import { prisma } from "@/lib/prisma" ...@@ -3,11 +3,12 @@ import { prisma } from "@/lib/prisma"
export async function DELETE( export async function DELETE(
request: NextRequest, request: NextRequest,
{ params }: { params: { id: string } } { params }: { params: Promise<{ id: string }> }
) { ) {
try { try {
const { id } = await params
await prisma.timeEntry.delete({ await prisma.timeEntry.delete({
where: { id: params.id }, where: { id },
}) })
return NextResponse.json({ success: true }) return NextResponse.json({ success: true })
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment