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.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);

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) {
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');
}