huge update
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import { NextRequest, NextResponse } from 'next/server';
|
||||
import { prisma } from '@/lib/prisma';
|
||||
import { apiCache } from '@/lib/cache';
|
||||
|
||||
export async function GET(
|
||||
request: NextRequest,
|
||||
@@ -35,20 +36,41 @@ export async function PUT(
|
||||
{ params }: { params: Promise<{ id: string }> }
|
||||
) {
|
||||
try {
|
||||
// Check if this is an admin request
|
||||
const isAdminRequest = request.headers.get('x-admin-request') === 'true';
|
||||
if (!isAdminRequest) {
|
||||
return NextResponse.json(
|
||||
{ error: 'Admin access required' },
|
||||
{ status: 403 }
|
||||
);
|
||||
}
|
||||
|
||||
const { id: idParam } = await params;
|
||||
const id = parseInt(idParam);
|
||||
const data = await request.json();
|
||||
|
||||
// Remove difficulty field if it exists (since we're removing it)
|
||||
const { difficulty, ...projectData } = data;
|
||||
|
||||
const project = await prisma.project.update({
|
||||
where: { id },
|
||||
data: { ...data, updatedAt: new Date() }
|
||||
data: {
|
||||
...projectData,
|
||||
updatedAt: new Date(),
|
||||
// Keep existing difficulty if not provided
|
||||
...(difficulty ? { difficulty } : {})
|
||||
}
|
||||
});
|
||||
|
||||
// Invalidate cache after successful update
|
||||
await apiCache.invalidateProject(id);
|
||||
await apiCache.invalidateAll();
|
||||
|
||||
return NextResponse.json(project);
|
||||
} catch (error) {
|
||||
console.error('Error updating project:', error);
|
||||
return NextResponse.json(
|
||||
{ error: 'Failed to update project' },
|
||||
{ error: 'Failed to update project', details: error instanceof Error ? error.message : 'Unknown error' },
|
||||
{ status: 500 }
|
||||
);
|
||||
}
|
||||
@@ -66,6 +88,10 @@ export async function DELETE(
|
||||
where: { id }
|
||||
});
|
||||
|
||||
// Invalidate cache after successful deletion
|
||||
await apiCache.invalidateProject(id);
|
||||
await apiCache.invalidateAll();
|
||||
|
||||
return NextResponse.json({ success: true });
|
||||
} catch (error) {
|
||||
console.error('Error deleting project:', error);
|
||||
|
||||
Reference in New Issue
Block a user