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:
@@ -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);
|
||||
|
||||
@@ -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');
|
||||
}
|
||||
|
||||
|
||||
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user