Refactor politics routes and service: Removed duplicate route for open politics in falukantRouter, updated falukantService to enhance logging for age validation in political applications, and ensured proper handling of open politics data in PoliticsView. This improves code clarity and debugging capabilities.

This commit is contained in:
Torsten Schulz (local)
2026-02-06 00:04:49 +01:00
parent 6b96ee9856
commit 56c38c04aa
3 changed files with 11 additions and 12 deletions

View File

@@ -76,10 +76,9 @@ router.get('/health', falukantController.getHealth);
router.post('/health', falukantController.healthActivity); router.post('/health', falukantController.healthActivity);
router.get('/politics/overview', falukantController.getPoliticsOverview); router.get('/politics/overview', falukantController.getPoliticsOverview);
router.get('/politics/open', falukantController.getOpenPolitics); router.get('/politics/open', falukantController.getOpenPolitics);
router.post('/politics/open', falukantController.applyForElections);
router.get('/politics/elections', falukantController.getElections); router.get('/politics/elections', falukantController.getElections);
router.post('/politics/elections', falukantController.vote); router.post('/politics/elections', falukantController.vote);
router.get('/politics/open', falukantController.getOpenPolitics);
router.post('/politics/open', falukantController.applyForElections);
router.get('/cities', falukantController.getRegions); router.get('/cities', falukantController.getRegions);
router.get('/products/price-in-region', falukantController.getProductPriceInRegion); router.get('/products/price-in-region', falukantController.getProductPriceInRegion);
router.get('/products/prices-in-region', falukantController.getAllProductPricesInRegion); router.get('/products/prices-in-region', falukantController.getAllProductPricesInRegion);

View File

@@ -4249,14 +4249,6 @@ class FalukantService extends BaseService {
}); });
} }
async getOpenPolitics(hashedUserId) {
const user = await this.getFalukantUserByHashedId(hashedUserId);
if (!user || user.character.nobleTitle.labelTr === 'noncivil') {
return [];
}
}
async getElections(hashedUserId) { async getElections(hashedUserId) {
const user = await this.getFalukantUserByHashedId(hashedUserId); const user = await this.getFalukantUserByHashedId(hashedUserId);
if (!user || user.character.nobleTitle.labelTr === 'noncivil') { if (!user || user.character.nobleTitle.labelTr === 'noncivil') {
@@ -4417,6 +4409,7 @@ class FalukantService extends BaseService {
const characterId = character.id; const characterId = character.id;
const ageDays = character.birthdate ? calcAge(character.birthdate) : 0; const ageDays = character.birthdate ? calcAge(character.birthdate) : 0;
const canApplyByAge = ageDays >= FalukantService.MIN_AGE_POLITICS_DAYS; const canApplyByAge = ageDays >= FalukantService.MIN_AGE_POLITICS_DAYS;
console.log('[getOpenPolitics] characterId=', characterId, 'birthdate=', character.birthdate, 'ageDays=', ageDays, 'MIN=', FalukantService.MIN_AGE_POLITICS_DAYS, 'canApplyByAge=', canApplyByAge);
const rows = await sequelize.query( const rows = await sequelize.query(
FalukantService.RECURSIVE_REGION_SEARCH, FalukantService.RECURSIVE_REGION_SEARCH,
{ {
@@ -4492,6 +4485,7 @@ class FalukantService extends BaseService {
}; };
}) })
.filter(election => !election.alreadyApplied); // Nur Positionen ohne bestehende Bewerbung .filter(election => !election.alreadyApplied); // Nur Positionen ohne bestehende Bewerbung
console.log('[getOpenPolitics] returning', result.length, 'entries, canApplyByAge on first:', result[0]?.canApplyByAge);
return result; return result;
} }
@@ -4508,7 +4502,9 @@ class FalukantService extends BaseService {
// 2) Mindestalter 16 (Spieljahre = 16 Tage Realzeit) // 2) Mindestalter 16 (Spieljahre = 16 Tage Realzeit)
const ageDays = character.birthdate ? calcAge(character.birthdate) : 0; const ageDays = character.birthdate ? calcAge(character.birthdate) : 0;
console.log('[applyForElections] characterId=', character.id, 'birthdate=', character.birthdate, 'ageDays=', ageDays, 'MIN=', FalukantService.MIN_AGE_POLITICS_DAYS);
if (ageDays < FalukantService.MIN_AGE_POLITICS_DAYS) { if (ageDays < FalukantService.MIN_AGE_POLITICS_DAYS) {
console.log('[applyForElections] rejected: too_young');
throw new Error('too_young'); throw new Error('too_young');
} }

View File

@@ -246,10 +246,14 @@ export default {
this.loading.openPolitics = true; this.loading.openPolitics = true;
try { try {
const { data } = await apiClient.get('/api/falukant/politics/open'); const { data } = await apiClient.get('/api/falukant/politics/open');
this.openPolitics = data; this.openPolitics = Array.isArray(data) ? data : [];
// Debug: Alters-Flag prüfen
if (this.openPolitics.length > 0) {
console.log('[PoliticsView] loadOpenPolitics: count=', this.openPolitics.length, 'first.canApplyByAge=', this.openPolitics[0].canApplyByAge, 'first.id=', this.openPolitics[0].id);
}
// Bereits beworbene Positionen vorselektieren, damit die Checkbox // Bereits beworbene Positionen vorselektieren, damit die Checkbox
// sichtbar markiert bleibt. // sichtbar markiert bleibt.
this.selectedApplications = data this.selectedApplications = this.openPolitics
.filter(e => e.alreadyApplied) .filter(e => e.alreadyApplied)
.map(e => e.id); .map(e => e.id);
} catch (err) { } catch (err) {