Improve the dahboard with the weather info
This commit is contained in:
@@ -67,18 +67,8 @@ export class ExternalService {
|
||||
return response;
|
||||
|
||||
} catch (error) {
|
||||
console.error('Failed to fetch weather from backend:', error);
|
||||
|
||||
// Fallback weather for Madrid (matching WeatherData schema)
|
||||
return {
|
||||
date: new Date().toISOString(),
|
||||
temperature: 18,
|
||||
description: 'Parcialmente nublado',
|
||||
precipitation: 0,
|
||||
humidity: 65,
|
||||
wind_speed: 10,
|
||||
source: 'fallback'
|
||||
};
|
||||
console.error('Failed to fetch weather from AEMET API via backend:', error);
|
||||
throw new Error(`Weather data unavailable: ${error instanceof Error ? error.message : 'AEMET API connection failed'}`);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -109,8 +99,8 @@ export class ExternalService {
|
||||
return [];
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Failed to fetch weather forecast:', error);
|
||||
return [];
|
||||
console.error('Failed to fetch weather forecast from AEMET API:', error);
|
||||
throw new Error(`Weather forecast unavailable: ${error instanceof Error ? error.message : 'AEMET API connection failed'}`);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -136,8 +126,8 @@ export class ExternalService {
|
||||
// Return backend response directly (matches WeatherData interface)
|
||||
return Array.isArray(response) ? response : response.data || [];
|
||||
} catch (error) {
|
||||
console.error('Failed to fetch historical weather:', error);
|
||||
return [];
|
||||
console.error('Failed to fetch historical weather from AEMET API:', error);
|
||||
throw new Error(`Historical weather data unavailable: ${error instanceof Error ? error.message : 'AEMET API connection failed'}`);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -160,17 +150,8 @@ export class ExternalService {
|
||||
// Return backend response directly (matches TrafficData interface)
|
||||
return response;
|
||||
} catch (error) {
|
||||
console.error('Failed to fetch traffic data:', error);
|
||||
|
||||
// Fallback traffic data (matching TrafficData schema)
|
||||
return {
|
||||
date: new Date().toISOString(),
|
||||
traffic_volume: 50,
|
||||
pedestrian_count: 25,
|
||||
congestion_level: 'medium',
|
||||
average_speed: 30,
|
||||
source: 'fallback'
|
||||
};
|
||||
console.error('Failed to fetch traffic data from external API:', error);
|
||||
throw new Error(`Traffic data unavailable: ${error instanceof Error ? error.message : 'External API connection failed'}`);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -194,8 +175,8 @@ export class ExternalService {
|
||||
// Return backend response directly (matches TrafficData interface)
|
||||
return Array.isArray(response) ? response : response.data || [];
|
||||
} catch (error) {
|
||||
console.error('Failed to fetch traffic forecast:', error);
|
||||
return [];
|
||||
console.error('Failed to fetch traffic forecast from external API:', error);
|
||||
throw new Error(`Traffic forecast unavailable: ${error instanceof Error ? error.message : 'External API connection failed'}`);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -221,8 +202,8 @@ export class ExternalService {
|
||||
// Return backend response directly (matches TrafficData interface)
|
||||
return Array.isArray(response) ? response : response.data || [];
|
||||
} catch (error) {
|
||||
console.error('Failed to fetch historical traffic:', error);
|
||||
return [];
|
||||
console.error('Failed to fetch historical traffic from external API:', error);
|
||||
throw new Error(`Historical traffic data unavailable: ${error instanceof Error ? error.message : 'External API connection failed'}`);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -241,11 +222,12 @@ export class ExternalService {
|
||||
};
|
||||
|
||||
try {
|
||||
// Test weather service
|
||||
// Test weather service (AEMET API)
|
||||
await this.getCurrentWeather(tenantId, 40.4168, -3.7038); // Madrid coordinates
|
||||
results.weather = true;
|
||||
} catch (error) {
|
||||
console.warn('Weather service connectivity test failed:', error);
|
||||
console.warn('AEMET weather service connectivity test failed:', error);
|
||||
results.weather = false;
|
||||
}
|
||||
|
||||
try {
|
||||
@@ -254,6 +236,7 @@ export class ExternalService {
|
||||
results.traffic = true;
|
||||
} catch (error) {
|
||||
console.warn('Traffic service connectivity test failed:', error);
|
||||
results.traffic = false;
|
||||
}
|
||||
|
||||
results.overall = results.weather && results.traffic;
|
||||
|
||||
Reference in New Issue
Block a user