From 3f569394214b84427cc0bf4ae9c1c753cd009eb8 Mon Sep 17 00:00:00 2001 From: "Torsten Schulz (local)" Date: Wed, 3 Dec 2025 13:39:09 +0100 Subject: [PATCH] Add detailed debug logging in getProductPricesInCities method of FalukantService - Introduced console logs to trace the execution flow and key variables in the getProductPricesInCities method, enhancing visibility into product price calculations. - Logged parameters such as productId, currentPrice, and currentRegionId at the start of the method. - Added logs for the number of cities and town worth entries found, as well as details when skipping the current city and adding results, improving traceability during price evaluations. - This update aims to facilitate debugging and performance monitoring by providing comprehensive insights into the pricing logic. --- backend/services/falukantService.js | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/backend/services/falukantService.js b/backend/services/falukantService.js index 42971a0..6a5aed6 100644 --- a/backend/services/falukantService.js +++ b/backend/services/falukantService.js @@ -3671,6 +3671,7 @@ class FalukantService extends BaseService { } async getProductPricesInCities(hashedUserId, productId, currentPrice, currentRegionId = null) { + console.log(`[getProductPricesInCities] Called: productId=${productId}, currentPrice=${currentPrice}, currentRegionId=${currentRegionId}`); const user = await this.getFalukantUserByHashedId(hashedUserId); const character = await FalukantCharacter.findOne({ where: { userId: user.id } }); if (!character) { @@ -3688,6 +3689,7 @@ class FalukantService extends BaseService { where: { characterId: character.id, productId: productId } }); const knowledgeFactor = knowledge?.knowledge || 0; + console.log(`[getProductPricesInCities] product.sellCost=${product.sellCost}, knowledgeFactor=${knowledgeFactor}`); // Alle Städte abrufen const cities = await RegionData.findAll({ @@ -3715,6 +3717,7 @@ class FalukantService extends BaseService { } ] }); + console.log(`[getProductPricesInCities] Found ${cities.length} cities`); // TownProductWorth für alle Städte und dieses Produkt abrufen const townWorths = await TownProductWorth.findAll({ @@ -3722,12 +3725,14 @@ class FalukantService extends BaseService { attributes: ['regionId', 'worthPercent'] }); const worthMap = new Map(townWorths.map(tw => [tw.regionId, tw.worthPercent])); + console.log(`[getProductPricesInCities] Found ${townWorths.length} townWorths entries`); // Für jede Stadt den Preis berechnen und Branch-Typ bestimmen const results = []; for (const city of cities) { // Aktuelle Stadt ausschließen if (currentRegionId && city.id === currentRegionId) { + console.log(`[getProductPricesInCities] Skipping current city: ${city.name} (${city.id})`); continue; } @@ -3742,6 +3747,8 @@ class FalukantService extends BaseService { const max = basePrice; const priceInCity = min + (max - min) * (knowledgeFactor / 100); + console.log(`[getProductPricesInCities] 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 +3764,7 @@ class FalukantService extends BaseService { } } + console.log(`[getProductPricesInCities] Adding ${city.name} to results: price=${priceInCity}, branchType=${branchType}`); results.push({ regionId: city.id, regionName: city.name, @@ -3766,6 +3774,7 @@ class FalukantService extends BaseService { } } + console.log(`[getProductPricesInCities] Returning ${results.length} cities with better prices`); // Sortiere nach Preis (höchster zuerst) results.sort((a, b) => b.price - a.price);