Refine city filtering in NPC creation process within AdminService

- Added explicit filtering for city-type regions to ensure only valid cities are processed during NPC creation.
- Enhanced logging to provide feedback on the number of cities found and their names, improving traceability in the NPC creation workflow.
- Updated comments for clarity on the importance of using city regions exclusively.
This commit is contained in:
Torsten Schulz (local)
2026-01-07 17:15:17 +01:00
parent c322eb1e5a
commit 0372d213c0

View File

@@ -1116,6 +1116,7 @@ class AdminService {
} = options; } = options;
// Berechne zuerst die Gesamtanzahl, um den Job richtig zu initialisieren // Berechne zuerst die Gesamtanzahl, um den Job richtig zu initialisieren
// WICHTIG: Nur Städte (city) verwenden, keine anderen Region-Typen
let targetRegions = []; let targetRegions = [];
if (regionIds && regionIds.length > 0) { if (regionIds && regionIds.length > 0) {
targetRegions = await RegionData.findAll({ targetRegions = await RegionData.findAll({
@@ -1125,7 +1126,8 @@ class AdminService {
include: [{ include: [{
model: RegionType, model: RegionType,
as: 'regionType', as: 'regionType',
where: { labelTr: 'city' } where: { labelTr: 'city' },
required: true // INNER JOIN - nur Regionen mit city-Type
}] }]
}); });
} else { } else {
@@ -1133,11 +1135,22 @@ class AdminService {
include: [{ include: [{
model: RegionType, model: RegionType,
as: 'regionType', as: 'regionType',
where: { labelTr: 'city' } where: { labelTr: 'city' },
required: true // INNER JOIN - nur Regionen mit city-Type
}] }]
}); });
} }
// Zusätzliche Sicherheit: Filtere explizit nach city-Type
targetRegions = targetRegions.filter(region => {
return region.regionType && region.regionType.labelTr === 'city';
});
console.log(`[createNPCs] Found ${targetRegions.length} cities (filtered)`);
if (targetRegions.length > 0) {
console.log(`[createNPCs] City names: ${targetRegions.map(r => r.name).join(', ')}`);
}
if (targetRegions.length === 0) { if (targetRegions.length === 0) {
throw new Error('No cities found'); throw new Error('No cities found');
} }