feat(FalukantService): update election filtering to include future dates and enhance eligibility checks
All checks were successful
Deploy to production / deploy (push) Successful in 1m55s

- 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.
This commit is contained in:
Torsten Schulz (local)
2026-05-08 08:30:03 +02:00
parent 0e572f8cbe
commit 0f7220d0b1

View File

@@ -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;
}