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:
@@ -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));
|
||||
|
||||
@@ -324,11 +324,18 @@ export default {
|
||||
|
||||
async submitApplications() {
|
||||
try {
|
||||
await apiClient.post(
|
||||
const response = await apiClient.post(
|
||||
'/api/falukant/politics/open',
|
||||
{ electionIds: this.selectedApplications }
|
||||
);
|
||||
// Speichere die IDs der erfolgreich beworbenen Positionen
|
||||
const appliedIds = response.data?.applied || [];
|
||||
// Lade die Daten neu
|
||||
await this.loadOpenPolitics();
|
||||
// Stelle sicher, dass alle bereits beworbenen Positionen (inkl. der gerade beworbenen) vorselektiert bleiben
|
||||
this.selectedApplications = this.openPolitics
|
||||
.filter(e => e.alreadyApplied || appliedIds.includes(e.id))
|
||||
.map(e => e.id);
|
||||
} catch (err) {
|
||||
console.error('Error submitting applications', err);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user