calendar and vehicle booking rework
This commit is contained in:
@@ -2,6 +2,7 @@ import { Request, Response } from 'express';
|
||||
import { ZodError } from 'zod';
|
||||
import bookingService from '../services/booking.service';
|
||||
import vehicleService from '../services/vehicle.service';
|
||||
import pool from '../config/database';
|
||||
import { permissionService } from '../services/permission.service';
|
||||
import {
|
||||
CreateBuchungSchema,
|
||||
@@ -43,6 +44,22 @@ function handleConflictError(res: Response, err: Error): boolean {
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
class BookingController {
|
||||
/**
|
||||
* GET /api/bookings/vehicles
|
||||
* Lightweight vehicle list for the booking form (no fahrzeuge:view needed).
|
||||
*/
|
||||
async getVehiclesForBooking(_req: Request, res: Response): Promise<void> {
|
||||
try {
|
||||
const result = await pool.query(
|
||||
'SELECT id, bezeichnung, amtliches_kennzeichen FROM fahrzeuge ORDER BY bezeichnung'
|
||||
);
|
||||
res.json({ success: true, data: result.rows });
|
||||
} catch (err) {
|
||||
logger.error('Failed to fetch vehicles for booking', err);
|
||||
res.status(500).json({ success: false, message: 'Fehler beim Laden der Fahrzeuge' });
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* GET /api/bookings/calendar?from=&to=&fahrzeugId=
|
||||
* Returns all non-cancelled bookings overlapping the given date range.
|
||||
|
||||
@@ -11,6 +11,7 @@ router.get('/calendar.ics', optionalAuth, bookingController.getIcalExport.bind(b
|
||||
|
||||
// ── Read-only (all authenticated users) ──────────────────────────────────────
|
||||
|
||||
router.get('/vehicles', authenticate, bookingController.getVehiclesForBooking.bind(bookingController));
|
||||
router.get('/calendar', authenticate, bookingController.getCalendarRange.bind(bookingController));
|
||||
router.get('/upcoming', authenticate, bookingController.getUpcoming.bind(bookingController));
|
||||
router.get('/availability', authenticate, bookingController.checkAvailability.bind(bookingController));
|
||||
|
||||
Reference in New Issue
Block a user