This commit is contained in:
Matthias Hochmeister
2026-03-13 19:23:39 +01:00
parent 02d9d808b2
commit bc6d09200a
15 changed files with 610 additions and 74 deletions

View File

@@ -25,8 +25,12 @@ function handleZodError(res: Response, err: ZodError): void {
}
function handleConflictError(res: Response, err: Error): boolean {
if (err.message?.includes('außer Dienst')) {
res.status(409).json({ success: false, message: err.message, reason: 'out_of_service' });
return true;
}
if (err.message?.includes('bereits gebucht')) {
res.status(409).json({ success: false, message: err.message });
res.status(409).json({ success: false, message: err.message, reason: 'booking_conflict' });
return true;
}
return false;
@@ -88,10 +92,27 @@ class BookingController {
.json({ success: false, message: 'fahrzeugId, from und to sind erforderlich' });
return;
}
const beginn = new Date(from as string);
const ende = new Date(to as string);
const outOfService = await bookingService.checkOutOfServiceConflict(
fahrzeugId as string, beginn, ende
);
if (outOfService) {
res.json({
success: true,
data: {
available: false,
reason: 'out_of_service',
ausserDienstVon: outOfService.ausser_dienst_von.toISOString(),
ausserDienstBis: outOfService.ausser_dienst_bis.toISOString(),
},
});
return;
}
const hasConflict = await bookingService.checkConflict(
fahrzeugId as string,
new Date(from as string),
new Date(to as string)
fahrzeugId as string, beginn, ende
);
res.json({ success: true, data: { available: !hasConflict } });
} catch (error) {