Enhance product price retrieval by including currentRegionId in FalukantController and FalukantService

- Updated the FalukantController to accept currentRegionId as a parameter for fetching product prices in cities.
- Modified the FalukantService to incorporate currentRegionId in the price calculation logic, allowing exclusion of the current region from results.
- Adjusted frontend components to pass currentRegionId, improving the accuracy of price comparisons and user experience.
This commit is contained in:
Torsten Schulz (local)
2025-12-03 08:39:30 +01:00
parent 6ec62af606
commit 4eeb5021ee
4 changed files with 14 additions and 11 deletions

View File

@@ -3670,7 +3670,7 @@ class FalukantService extends BaseService {
return { price };
}
async getProductPricesInCities(hashedUserId, productId, currentPrice) {
async getProductPricesInCities(hashedUserId, productId, currentPrice, currentRegionId = null) {
const user = await this.getFalukantUserByHashedId(hashedUserId);
const character = await FalukantCharacter.findOne({ where: { userId: user.id } });
if (!character) {
@@ -3725,8 +3725,12 @@ class FalukantService extends BaseService {
// Für jede Stadt den Preis berechnen und Branch-Typ bestimmen
const results = [];
console.log(`[getProductPricesInCities] productId: ${productId}, currentPrice: ${currentPrice}, knowledgeFactor: ${knowledgeFactor}, product.sellCost: ${product.sellCost}, cities: ${cities.length}`);
for (const city of cities) {
// Aktuelle Stadt ausschließen
if (currentRegionId && city.id === currentRegionId) {
continue;
}
// Regionaler Preis-Faktor (worthPercent zwischen 40-60)
const worthPercent = worthMap.get(city.id) || 50; // Default 50% wenn nicht gefunden
@@ -3738,11 +3742,9 @@ 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 + 0.001}`);
// Nur Städte zurückgeben, wo der Preis höher ist
// Verwende eine kleine Toleranz (0.001) um Rundungsfehler zu vermeiden
if (priceInCity > currentPrice + 0.001) {
// Keine Toleranz, da wir die aktuelle Stadt bereits ausschließen
if (priceInCity > currentPrice) {
// Branch-Typ bestimmen
let branchType = null; // null = kein Branch
if (city.branches && city.branches.length > 0) {
@@ -3767,7 +3769,6 @@ class FalukantService extends BaseService {
// Sortiere nach Preis (höchster zuerst)
results.sort((a, b) => b.price - a.price);
console.log(`[getProductPricesInCities] Returning ${results.length} cities with better prices`);
return results;
}