From 56c38c04aa53f049beaf1ab78602c863f784d95b Mon Sep 17 00:00:00 2001 From: "Torsten Schulz (local)" Date: Fri, 6 Feb 2026 00:04:49 +0100 Subject: [PATCH] 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. --- backend/routers/falukantRouter.js | 3 +-- backend/services/falukantService.js | 12 ++++-------- frontend/src/views/falukant/PoliticsView.vue | 8 ++++++-- 3 files changed, 11 insertions(+), 12 deletions(-) diff --git a/backend/routers/falukantRouter.js b/backend/routers/falukantRouter.js index 8b96c68..2f88afc 100644 --- a/backend/routers/falukantRouter.js +++ b/backend/routers/falukantRouter.js @@ -76,10 +76,9 @@ router.get('/health', falukantController.getHealth); router.post('/health', falukantController.healthActivity); router.get('/politics/overview', falukantController.getPoliticsOverview); router.get('/politics/open', falukantController.getOpenPolitics); +router.post('/politics/open', falukantController.applyForElections); router.get('/politics/elections', falukantController.getElections); 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('/products/price-in-region', falukantController.getProductPriceInRegion); router.get('/products/prices-in-region', falukantController.getAllProductPricesInRegion); diff --git a/backend/services/falukantService.js b/backend/services/falukantService.js index af3c885..f90eaeb 100644 --- a/backend/services/falukantService.js +++ b/backend/services/falukantService.js @@ -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) { const user = await this.getFalukantUserByHashedId(hashedUserId); if (!user || user.character.nobleTitle.labelTr === 'noncivil') { @@ -4417,6 +4409,7 @@ class FalukantService extends BaseService { const characterId = character.id; const ageDays = character.birthdate ? calcAge(character.birthdate) : 0; 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( FalukantService.RECURSIVE_REGION_SEARCH, { @@ -4492,6 +4485,7 @@ class FalukantService extends BaseService { }; }) .filter(election => !election.alreadyApplied); // Nur Positionen ohne bestehende Bewerbung + console.log('[getOpenPolitics] returning', result.length, 'entries, canApplyByAge on first:', result[0]?.canApplyByAge); return result; } @@ -4508,7 +4502,9 @@ class FalukantService extends BaseService { // 2) Mindestalter 16 (Spieljahre = 16 Tage Realzeit) 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) { + console.log('[applyForElections] rejected: too_young'); throw new Error('too_young'); } diff --git a/frontend/src/views/falukant/PoliticsView.vue b/frontend/src/views/falukant/PoliticsView.vue index 4360b7f..1f8b6bb 100644 --- a/frontend/src/views/falukant/PoliticsView.vue +++ b/frontend/src/views/falukant/PoliticsView.vue @@ -246,10 +246,14 @@ export default { this.loading.openPolitics = true; try { 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 // sichtbar markiert bleibt. - this.selectedApplications = data + this.selectedApplications = this.openPolitics .filter(e => e.alreadyApplied) .map(e => e.id); } catch (err) {