From 0f7220d0b119a5137804b96425df9cc283345751 Mon Sep 17 00:00:00 2001 From: "Torsten Schulz (local)" Date: Fri, 8 May 2026 08:30:03 +0200 Subject: [PATCH] feat(FalukantService): update election filtering to include future dates and enhance eligibility checks - Modified the election query to filter for upcoming election dates instead of past ones, ensuring only future positions are considered. - Added checks for prerequisites in election eligibility, allowing positions without prerequisites to be selectable, improving user experience in the application. --- backend/services/falukantService.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/backend/services/falukantService.js b/backend/services/falukantService.js index 1b6f0b7..bd94c1c 100644 --- a/backend/services/falukantService.js +++ b/backend/services/falukantService.js @@ -6907,10 +6907,12 @@ class FalukantService extends BaseService { ]; const allTypes = await PoliticalOfficeType.findAll({ attributes: ['id', 'name'] }); const nameToId = Object.fromEntries(allTypes.map(t => [t.name, t.id])); + const now = new Date(); const openPositions = await Election.findAll({ where: { regionId: { [Op.in]: regionIds }, - date: { [Op.lt]: new Date() } + // "Anstehende Neuwahl-Positionen": nur zukünftige/kommende Wahltermine + date: { [Op.gte]: now } }, include: [ { @@ -6941,6 +6943,8 @@ class FalukantService extends BaseService { }) .filter(election => { const prereqs = election.officeType.prerequisites || []; + // Wenn es keine Voraussetzungen gibt, ist die Position grundsätzlich wählbar. + if (!Array.isArray(prereqs) || prereqs.length === 0) return true; return prereqs.some(pr => { const jobs = pr.prerequisite.jobs; if (!Array.isArray(jobs) || jobs.length === 0) return true; @@ -6972,7 +6976,6 @@ class FalukantService extends BaseService { canApplyByAge }; }) - .filter(election => !election.alreadyApplied); // Nur Positionen ohne bestehende Bewerbung return result; }