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