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
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:
@@ -6907,10 +6907,12 @@ class FalukantService extends BaseService {
|
|||||||
];
|
];
|
||||||
const allTypes = await PoliticalOfficeType.findAll({ attributes: ['id', 'name'] });
|
const allTypes = await PoliticalOfficeType.findAll({ attributes: ['id', 'name'] });
|
||||||
const nameToId = Object.fromEntries(allTypes.map(t => [t.name, t.id]));
|
const nameToId = Object.fromEntries(allTypes.map(t => [t.name, t.id]));
|
||||||
|
const now = new Date();
|
||||||
const openPositions = await Election.findAll({
|
const openPositions = await Election.findAll({
|
||||||
where: {
|
where: {
|
||||||
regionId: { [Op.in]: regionIds },
|
regionId: { [Op.in]: regionIds },
|
||||||
date: { [Op.lt]: new Date() }
|
// "Anstehende Neuwahl-Positionen": nur zukünftige/kommende Wahltermine
|
||||||
|
date: { [Op.gte]: now }
|
||||||
},
|
},
|
||||||
include: [
|
include: [
|
||||||
{
|
{
|
||||||
@@ -6941,6 +6943,8 @@ class FalukantService extends BaseService {
|
|||||||
})
|
})
|
||||||
.filter(election => {
|
.filter(election => {
|
||||||
const prereqs = election.officeType.prerequisites || [];
|
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 => {
|
return prereqs.some(pr => {
|
||||||
const jobs = pr.prerequisite.jobs;
|
const jobs = pr.prerequisite.jobs;
|
||||||
if (!Array.isArray(jobs) || jobs.length === 0) return true;
|
if (!Array.isArray(jobs) || jobs.length === 0) return true;
|
||||||
@@ -6972,7 +6976,6 @@ class FalukantService extends BaseService {
|
|||||||
canApplyByAge
|
canApplyByAge
|
||||||
};
|
};
|
||||||
})
|
})
|
||||||
.filter(election => !election.alreadyApplied); // Nur Positionen ohne bestehende Bewerbung
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user