42 lines
988 B
TypeScript
42 lines
988 B
TypeScript
import { NextRequest, NextResponse } from 'next/server';
|
|
import { prisma } from '@/lib/prisma';
|
|
|
|
export async function GET(request: NextRequest) {
|
|
try {
|
|
const searchParams = request.nextUrl.searchParams;
|
|
const locationSlug = searchParams.get('location');
|
|
|
|
if (!locationSlug) {
|
|
return NextResponse.json(
|
|
{ error: 'Location parameter required' },
|
|
{ status: 400 }
|
|
);
|
|
}
|
|
|
|
const location = await prisma.location.findUnique({
|
|
where: { slug: locationSlug },
|
|
});
|
|
|
|
if (!location) {
|
|
return NextResponse.json(
|
|
{ error: 'Location not found' },
|
|
{ status: 404 }
|
|
);
|
|
}
|
|
|
|
const prices = await prisma.priceConfig.findMany({
|
|
where: {
|
|
locationId: location.id,
|
|
},
|
|
});
|
|
|
|
return NextResponse.json({ prices });
|
|
} catch (error) {
|
|
console.error('Prices fetch error:', error);
|
|
return NextResponse.json(
|
|
{ error: 'Internal server error' },
|
|
{ status: 500 }
|
|
);
|
|
}
|
|
}
|