Initial commit - SaveTheMoment Atlas Basis-Setup
This commit is contained in:
41
app/api/prices/route.ts
Normal file
41
app/api/prices/route.ts
Normal file
@@ -0,0 +1,41 @@
|
||||
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 }
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user