fix: corrigir tipagem de params para Next.js 15 nas APIs
This commit is contained in:
@@ -1,15 +1,15 @@
|
||||
import { NextResponse } from 'next/server';
|
||||
import { NextRequest, NextResponse } from 'next/server';
|
||||
import prisma from '@/lib/prisma';
|
||||
import { Prisma } from '@prisma/client';
|
||||
|
||||
type Params = {
|
||||
params: { id: string };
|
||||
};
|
||||
|
||||
export async function GET(_request: Request, { params }: Params) {
|
||||
export async function GET(
|
||||
_request: NextRequest,
|
||||
{ params }: { params: Promise<{ id: string }> }
|
||||
) {
|
||||
try {
|
||||
const { id } = await params;
|
||||
const project = await prisma.project.findUnique({
|
||||
where: { id: params.id },
|
||||
where: { id },
|
||||
});
|
||||
|
||||
if (!project) {
|
||||
@@ -23,8 +23,12 @@ export async function GET(_request: Request, { params }: Params) {
|
||||
}
|
||||
}
|
||||
|
||||
export async function PATCH(request: Request, { params }: Params) {
|
||||
export async function PATCH(
|
||||
request: NextRequest,
|
||||
{ params }: { params: Promise<{ id: string }> }
|
||||
) {
|
||||
try {
|
||||
const { id } = await params;
|
||||
const body = await request.json();
|
||||
const updateData: Record<string, unknown> = {};
|
||||
|
||||
@@ -43,7 +47,7 @@ export async function PATCH(request: Request, { params }: Params) {
|
||||
}
|
||||
|
||||
const project = await prisma.project.update({
|
||||
where: { id: params.id },
|
||||
where: { id },
|
||||
data: updateData,
|
||||
});
|
||||
|
||||
@@ -59,10 +63,14 @@ export async function PATCH(request: Request, { params }: Params) {
|
||||
}
|
||||
}
|
||||
|
||||
export async function DELETE(_request: Request, { params }: Params) {
|
||||
export async function DELETE(
|
||||
_request: NextRequest,
|
||||
{ params }: { params: Promise<{ id: string }> }
|
||||
) {
|
||||
try {
|
||||
const { id } = await params;
|
||||
await prisma.project.delete({
|
||||
where: { id: params.id },
|
||||
where: { id },
|
||||
});
|
||||
return NextResponse.json({ success: true });
|
||||
} catch (error) {
|
||||
|
||||
Reference in New Issue
Block a user