Nichtbetrachten und Daten zusammen
This commit is contained in:
30
src/app/api/hotels/[id]/prices/route.ts
Normal file
30
src/app/api/hotels/[id]/prices/route.ts
Normal file
@@ -0,0 +1,30 @@
|
||||
import { NextRequest, NextResponse } from 'next/server';
|
||||
import { query } from '@/lib/db';
|
||||
|
||||
export const dynamic = 'force-dynamic';
|
||||
|
||||
export async function GET(req: NextRequest, { params }: { params: { id: string } }) {
|
||||
try {
|
||||
const { id } = params;
|
||||
|
||||
const res = await query(
|
||||
`SELECT
|
||||
id,
|
||||
price_numeric::float AS price,
|
||||
price_per_night::float AS price_per_night,
|
||||
price_per_person::float AS price_per_person,
|
||||
nights,
|
||||
persons,
|
||||
tracked_at AS created_at
|
||||
FROM hotel_price_history
|
||||
WHERE hotel_id::text = $1::text
|
||||
ORDER BY tracked_at ASC`,
|
||||
[id]
|
||||
);
|
||||
|
||||
return NextResponse.json({ success: true, prices: res.rows });
|
||||
} catch (error: any) {
|
||||
console.error('Fehler beim Laden der Preishistorie:', error.message);
|
||||
return NextResponse.json({ success: false, error: error.message, prices: [] }, { status: 500 });
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user