Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 | 1x 1x 1x 1x 1x 1x | import { NextResponse } from 'next/server'
import { prisma } from '@/lib/prisma'
import { checkAdminAuth } from '@/lib/auth-check'
// POST /api/admin/category-images - Create or update category image (Admin only)
export async function POST(request: Request) {
const authError = await checkAdminAuth()
Iif (authError) return authError
try {
const body = await request.json()
const categoryImage = await prisma.categoryImage.upsert({
where: { categoryName: body.categoryName },
update: { imageUrl: body.imageUrl },
create: {
categoryName: body.categoryName,
imageUrl: body.imageUrl,
},
})
return NextResponse.json(categoryImage, { status: 201 })
} catch (error) {
console.error('Error saving category image:', error)
return NextResponse.json({ error: 'Failed to save category image' }, { status: 500 })
}
}
|