Refactor availability status logic in FalukantService
- Enhanced the logic for determining the availability status of vehicles based on the 'availableFrom' date. - Added conditions to differentiate between 'building' and 'available' statuses, improving clarity and accuracy in status reporting. - Updated comments for better understanding of the code flow.
This commit is contained in:
@@ -660,11 +660,18 @@ class FalukantService extends BaseService {
|
||||
if (hasTransportHere) {
|
||||
// verknüpft mit Transport in dieser Region = unterwegs
|
||||
status = 'travelling';
|
||||
} else if (plain.availableFrom && new Date(plain.availableFrom).getTime() > now.getTime()) {
|
||||
// kein Transport, aber Verfügbarkeit liegt in der Zukunft = im Bau
|
||||
status = 'building';
|
||||
} else if (plain.availableFrom) {
|
||||
const availableFromTime = new Date(plain.availableFrom).getTime();
|
||||
const nowTime = now.getTime();
|
||||
// Verfügbarkeit liegt in der Zukunft = im Bau oder in Reparatur
|
||||
if (availableFromTime > nowTime) {
|
||||
status = 'building';
|
||||
} else {
|
||||
// Verfügbarkeit erreicht = verfügbar
|
||||
status = 'available';
|
||||
}
|
||||
} else {
|
||||
// kein Transport und Verfügbarkeit erreicht = verfügbar
|
||||
// Kein availableFrom gesetzt = verfügbar (Fallback)
|
||||
status = 'available';
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user