mirror of
https://github.com/R0m1k3/LogiFlow.git
synced 2026-10-11 17:27:31 +02:00
Merge pull request #140 from R0m1k3/1.1
Handle duplicate weather data entries and improve historical fetching
This commit is contained in:
3 files changed
+26
-11
No files matched your search
+1
-1
@@ -2,4 +2,4 @@
|
||||
# https://curl.se/docs/http-cookies.html
|
||||
# This file was generated by libcurl! Edit at your own risk.
|
||||
|
||||
#HttpOnly_localhost FALSE / FALSE 1755332443 connect.sid s%3Ag_FLmIyfx_N-5QZpTU_E9Tq4Ex9FFnxY.A1JSe5Hq9weYwtimsv7bQq6FLWLDcH6CBt%2FeZnBzlus
|
||||
#HttpOnly_localhost FALSE / FALSE 1755332748 connect.sid s%3ATGkcy9eVr4-9HEcJjuFU9AZrRq4VYOLY.TsQjtj4uhpU1n9T1IDgVMkeiQAi8SdziEoQFRooTS8w
|
||||
+20
-4
@@ -2864,25 +2864,41 @@ RÉSUMÉ DU SCAN
|
||||
|
||||
// Fetch current year data if not in cache
|
||||
if (!currentYearData) {
|
||||
console.log("🌤️ Fetching current weather data from API");
|
||||
console.log("🌤️ [FETCH] Fetching current weather data from API");
|
||||
const apiData = await weatherService.fetchCurrentWeather(settings);
|
||||
if (apiData) {
|
||||
const weatherData = weatherService.convertApiDataToWeatherData(apiData, settings.location, true);
|
||||
if (weatherData) {
|
||||
currentYearData = await storage.createWeatherData(weatherData);
|
||||
try {
|
||||
currentYearData = await storage.createWeatherData(weatherData);
|
||||
console.log("✅ [CACHE] Current year data saved to cache");
|
||||
} catch (error: any) {
|
||||
console.warn("⚠️ [CACHE] Could not save current year data (may already exist):", error.message);
|
||||
// Récupérer les données existantes au lieu de créer
|
||||
currentYearData = await storage.getWeatherData(today, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Fetch previous year data if not in cache
|
||||
if (!previousYearData) {
|
||||
console.log("🌤️ Fetching previous year weather data from API");
|
||||
console.log("🌤️ [FETCH] Fetching previous year weather data from API");
|
||||
const apiData = await weatherService.fetchPreviousYearWeather(settings, previousYearDate);
|
||||
if (apiData) {
|
||||
const weatherData = weatherService.convertApiDataToWeatherData(apiData, settings.location, false);
|
||||
if (weatherData) {
|
||||
previousYearData = await storage.createWeatherData(weatherData);
|
||||
try {
|
||||
previousYearData = await storage.createWeatherData(weatherData);
|
||||
console.log("✅ [CACHE] Previous year data saved to cache");
|
||||
} catch (error: any) {
|
||||
console.warn("⚠️ [CACHE] Could not save previous year data (may already exist):", error.message);
|
||||
// Récupérer les données existantes au lieu de créer
|
||||
previousYearData = await storage.getWeatherData(previousYearDate, false);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
console.warn("⚠️ [HISTORY] Could not fetch historical data - continuing with current year only");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { WeatherData, WeatherSettings } from "../shared/schema.js";
|
||||
import { WeatherData, WeatherSettings, InsertWeatherData } from "../shared/schema.js";
|
||||
|
||||
export interface WeatherApiResponse {
|
||||
days: Array<{
|
||||
@@ -72,7 +72,7 @@ export class WeatherService {
|
||||
/**
|
||||
* Convertit les données de l'API en format WeatherData
|
||||
*/
|
||||
convertApiDataToWeatherData(apiData: WeatherApiResponse, location: string, isCurrentYear: boolean): WeatherData | null {
|
||||
convertApiDataToWeatherData(apiData: WeatherApiResponse, location: string, isCurrentYear: boolean): InsertWeatherData | null {
|
||||
if (!apiData.days || apiData.days.length === 0) {
|
||||
return null;
|
||||
}
|
||||
@@ -80,16 +80,15 @@ export class WeatherService {
|
||||
const todayData = apiData.days[0];
|
||||
|
||||
return {
|
||||
id: 0, // Sera généré par la base de données
|
||||
// Pas d'ID - sera auto-généré par PostgreSQL serial
|
||||
date: todayData.datetime,
|
||||
location,
|
||||
tempMax: todayData.tempmax.toString(),
|
||||
tempMin: todayData.tempmin.toString(),
|
||||
icon: todayData.icon,
|
||||
conditions: todayData.conditions,
|
||||
isCurrentYear,
|
||||
createdAt: new Date(),
|
||||
updatedAt: new Date()
|
||||
isCurrentYear
|
||||
// Pas de createdAt/updatedAt - gérés par la base de données
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user