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: RegionType, as: 'regionType', attributes: ['labelTr'] }
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{ model: Candidate, as: 'candidates' },
|
{
|
||||||
|
model: Candidate,
|
||||||
|
as: 'candidates',
|
||||||
|
required: false
|
||||||
|
},
|
||||||
{
|
{
|
||||||
model: PoliticalOfficeType, as: 'officeType',
|
model: PoliticalOfficeType, as: 'officeType',
|
||||||
include: [{ model: PoliticalOfficePrerequisite, as: 'prerequisites' }]
|
include: [{ model: PoliticalOfficePrerequisite, as: 'prerequisites' }]
|
||||||
@@ -3569,10 +3573,11 @@ class FalukantService extends BaseService {
|
|||||||
return { applied: [], skipped: electionIds };
|
return { applied: [], skipped: electionIds };
|
||||||
}
|
}
|
||||||
|
|
||||||
// 3) Ermittle die heute offenen Wahlen, auf die er zugreifen darf
|
// 3) Ermittle die offenen Wahlen, auf die er zugreifen darf
|
||||||
// (getElections liefert id, officeType, region, date, postsToFill, candidates, voted…)
|
// Verwende getOpenPolitics statt getElections, da getOpenPolitics die gleichen Wahlen
|
||||||
const openElections = await this.getElections(hashedUserId);
|
// zurückgibt, die im Frontend angezeigt werden
|
||||||
const allowedIds = new Set(openElections.map(e => e.id));
|
const openPolitics = await this.getOpenPolitics(hashedUserId);
|
||||||
|
const allowedIds = new Set(openPolitics.map(e => e.id));
|
||||||
|
|
||||||
// 4) Filter alle electionIds auf gültige/erlaubte
|
// 4) Filter alle electionIds auf gültige/erlaubte
|
||||||
const toTry = electionIds.filter(id => allowedIds.has(id));
|
const toTry = electionIds.filter(id => allowedIds.has(id));
|
||||||
|
|||||||
@@ -324,11 +324,18 @@ export default {
|
|||||||
|
|
||||||
async submitApplications() {
|
async submitApplications() {
|
||||||
try {
|
try {
|
||||||
await apiClient.post(
|
const response = await apiClient.post(
|
||||||
'/api/falukant/politics/open',
|
'/api/falukant/politics/open',
|
||||||
{ electionIds: this.selectedApplications }
|
{ electionIds: this.selectedApplications }
|
||||||
);
|
);
|
||||||
|
// Speichere die IDs der erfolgreich beworbenen Positionen
|
||||||
|
const appliedIds = response.data?.applied || [];
|
||||||
|
// Lade die Daten neu
|
||||||
await this.loadOpenPolitics();
|
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) {
|
} catch (err) {
|
||||||
console.error('Error submitting applications', err);
|
console.error('Error submitting applications', err);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user