This commit is contained in:
@@ -4,9 +4,12 @@ import prisma from '../../../../lib/prisma'
|
||||
type Params = { params: Promise<{ id: string }> }
|
||||
|
||||
// GET /api/blog/[id]
|
||||
export async function GET(_request: NextRequest, { params }: Params) {
|
||||
export async function GET(
|
||||
_request: NextRequest,
|
||||
context: { params: Promise<{ id: string }> }
|
||||
): Promise<Response> {
|
||||
try {
|
||||
const { id } = await params
|
||||
const { id } = await context.params
|
||||
const post = await prisma.blogPost.findUnique({ where: { id } })
|
||||
if (!post) return NextResponse.json({ error: 'Non trouvé' }, { status: 404 })
|
||||
return NextResponse.json(post)
|
||||
@@ -17,9 +20,12 @@ export async function GET(_request: NextRequest, { params }: Params) {
|
||||
}
|
||||
|
||||
// PATCH /api/blog/[id]
|
||||
export async function PATCH(request: NextRequest, { params }: Params) {
|
||||
export async function PATCH(
|
||||
request: NextRequest,
|
||||
context: { params: Promise<{ id: string }> }
|
||||
): Promise<Response> {
|
||||
try {
|
||||
const { id } = await params
|
||||
const { id } = await context.params
|
||||
const body = await request.json()
|
||||
const post = await prisma.blogPost.update({ where: { id }, data: body })
|
||||
return NextResponse.json(post)
|
||||
@@ -30,9 +36,12 @@ export async function PATCH(request: NextRequest, { params }: Params) {
|
||||
}
|
||||
|
||||
// DELETE /api/blog/[id]
|
||||
export async function DELETE(_request: NextRequest, { params }: Params) {
|
||||
export async function DELETE(
|
||||
_request: NextRequest,
|
||||
context: { params: Promise<{ id: string }> }
|
||||
): Promise<Response> {
|
||||
try {
|
||||
const { id } = await params
|
||||
const { id } = await context.params
|
||||
await prisma.blogPost.delete({ where: { id } })
|
||||
return NextResponse.json({ success: true })
|
||||
} catch (error) {
|
||||
|
||||
Reference in New Issue
Block a user