From 5d01b24c2de89b26365d914390dcaee2ec4d0941 Mon Sep 17 00:00:00 2001 From: "Torsten Schulz (local)" Date: Wed, 3 Dec 2025 08:44:45 +0100 Subject: [PATCH] Add debug logging for carrot product pricing in FalukantService - Introduced console logs to trace the price calculation process specifically for the carrot product (productId: 3). - Enhanced visibility into the evaluation of cities and the resulting prices, aiding in debugging and performance monitoring. - Logged details when skipping the current city, calculating prices, and adding cities to the results, improving traceability of pricing logic. --- backend/services/falukantService.js | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/backend/services/falukantService.js b/backend/services/falukantService.js index 42971a0..57b5386 100644 --- a/backend/services/falukantService.js +++ b/backend/services/falukantService.js @@ -3725,9 +3725,16 @@ class FalukantService extends BaseService { // Für jede Stadt den Preis berechnen und Branch-Typ bestimmen const results = []; + const isCarrot = productId === 3; // Debug für Karotten + if (isCarrot) { + console.log(`[getProductPricesInCities CARROT] productId: ${productId}, currentPrice: ${currentPrice}, currentRegionId: ${currentRegionId}, knowledgeFactor: ${knowledgeFactor}, product.sellCost: ${product.sellCost}, cities: ${cities.length}`); + } for (const city of cities) { // Aktuelle Stadt ausschließen if (currentRegionId && city.id === currentRegionId) { + if (isCarrot) { + console.log(`[getProductPricesInCities CARROT] Skipping current city: ${city.name} (${city.id})`); + } continue; } @@ -3742,6 +3749,10 @@ class FalukantService extends BaseService { const max = basePrice; const priceInCity = min + (max - min) * (knowledgeFactor / 100); + if (isCarrot) { + console.log(`[getProductPricesInCities CARROT] City: ${city.name} (${city.id}), worthPercent: ${worthPercent}, basePrice: ${basePrice}, priceInCity: ${priceInCity}, currentPrice: ${currentPrice}, isBetter: ${priceInCity > currentPrice}`); + } + // Nur Städte zurückgeben, wo der Preis höher ist // Keine Toleranz, da wir die aktuelle Stadt bereits ausschließen if (priceInCity > currentPrice) { @@ -3757,6 +3768,10 @@ class FalukantService extends BaseService { } } + if (isCarrot) { + console.log(`[getProductPricesInCities CARROT] Adding ${city.name} to results: price=${priceInCity}, branchType=${branchType}`); + } + results.push({ regionId: city.id, regionName: city.name, @@ -3765,6 +3780,10 @@ class FalukantService extends BaseService { }); } } + + if (isCarrot) { + console.log(`[getProductPricesInCities CARROT] Returning ${results.length} cities with better prices:`, results.map(r => `${r.regionName} (${r.price})`).join(', ')); + } // Sortiere nach Preis (höchster zuerst) results.sort((a, b) => b.price - a.price);