Fix image handling to support category, room_id, and location_target fields
This commit is contained in:
@@ -5,7 +5,7 @@ import { db } from '@/lib/db';
|
||||
export async function GET() {
|
||||
try {
|
||||
await requireRole('admin');
|
||||
const { rows } = await db.query('SELECT id, filename, uploaded_at FROM images ORDER BY uploaded_at DESC');
|
||||
const { rows } = await db.query('SELECT id, filename, category, room_id, location_target, uploaded_at FROM images ORDER BY uploaded_at DESC');
|
||||
return NextResponse.json({ images: rows, count: rows.length });
|
||||
} catch (error) {
|
||||
if ((error as Error).message === 'Unauthorized') {
|
||||
@@ -20,15 +20,15 @@ export async function POST(request: NextRequest) {
|
||||
try {
|
||||
await requireRole('admin');
|
||||
const body = await request.json();
|
||||
const { filename, data } = body;
|
||||
const { filename, data, category, room_id, location_target } = body;
|
||||
|
||||
if (!filename || !data) {
|
||||
return NextResponse.json({ error: 'Missing filename or data' }, { status: 400 });
|
||||
}
|
||||
|
||||
const { rows } = await db.query(
|
||||
'INSERT INTO images (filename, data) VALUES ($1, $2) RETURNING id, filename, uploaded_at',
|
||||
[filename, data]
|
||||
'INSERT INTO images (filename, data, category, room_id, location_target) VALUES ($1, $2, $3, $4, $5) RETURNING id, filename, category, room_id, location_target, uploaded_at',
|
||||
[filename, data, category || 'other', room_id || null, location_target || 'gallery']
|
||||
);
|
||||
|
||||
return NextResponse.json({ image: rows[0] });
|
||||
|
||||
Reference in New Issue
Block a user