Update FalukantService and PoliticsView to enhance election data handling

- Modified the FalukantService to use getOpenPolitics instead of getElections for retrieving accessible elections, improving alignment with frontend data display.
- Updated the PoliticsView to handle the response from the application submission more effectively, ensuring that already applied positions remain pre-selected after submission.
- These changes aim to streamline the election data flow and enhance user experience in the application process.
This commit is contained in:
Torsten Schulz (local)
2025-12-03 17:19:13 +01:00
parent d6ea09b3e2
commit e5ef334f7c
2 changed files with 18 additions and 6 deletions

View File

@@ -3510,7 +3510,11 @@ class FalukantService extends BaseService {
{ model: RegionType, as: 'regionType', attributes: ['labelTr'] }
]
},
{ model: Candidate, as: 'candidates' },
{
model: Candidate,
as: 'candidates',
required: false
},
{
model: PoliticalOfficeType, as: 'officeType',
include: [{ model: PoliticalOfficePrerequisite, as: 'prerequisites' }]
@@ -3569,10 +3573,11 @@ class FalukantService extends BaseService {
return { applied: [], skipped: electionIds };
}
// 3) Ermittle die heute offenen Wahlen, auf die er zugreifen darf
// (getElections liefert id, officeType, region, date, postsToFill, candidates, voted…)
const openElections = await this.getElections(hashedUserId);
const allowedIds = new Set(openElections.map(e => e.id));
// 3) Ermittle die offenen Wahlen, auf die er zugreifen darf
// Verwende getOpenPolitics statt getElections, da getOpenPolitics die gleichen Wahlen
// zurückgibt, die im Frontend angezeigt werden
const openPolitics = await this.getOpenPolitics(hashedUserId);
const allowedIds = new Set(openPolitics.map(e => e.id));
// 4) Filter alle electionIds auf gültige/erlaubte
const toTry = electionIds.filter(id => allowedIds.has(id));