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);