update
This commit is contained in:
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user