feat(falukant): add noble title level to election eligibility checks and improve election filtering logic
This commit is contained in:
@@ -960,7 +960,7 @@ class FalukantService extends BaseService {
|
||||
include: [
|
||||
{ model: FalukantPredefineFirstname, as: 'definedFirstName', attributes: ['name'] },
|
||||
{ model: FalukantPredefineLastname, as: 'definedLastName', attributes: ['name'] },
|
||||
{ model: TitleOfNobility, as: 'nobleTitle', attributes: ['labelTr', 'id'] }
|
||||
{ model: TitleOfNobility, as: 'nobleTitle', attributes: ['labelTr', 'id', 'level'] }
|
||||
],
|
||||
// reputation: für Adel-Voraussetzungen u.a. (checkReputationRequirement nutzt user.character ohne Nachladen)
|
||||
attributes: ['id', 'birthdate', 'gender', 'moodId', 'health', 'reputation']
|
||||
@@ -6916,9 +6916,20 @@ class FalukantService extends BaseService {
|
||||
|
||||
async getElections(hashedUserId) {
|
||||
const user = await this.getFalukantUserByHashedId(hashedUserId);
|
||||
if (!user || user.character.nobleTitle.labelTr === 'noncivil') {
|
||||
const character = user?.character;
|
||||
if (!character || Number(character.nobleTitle?.level || 0) < 2) {
|
||||
return [];
|
||||
}
|
||||
|
||||
// Wahlberechtigung: Das Einstiegsamt (ID 1, assessor) wird von allen
|
||||
// Bürgern oder höheren Ständen gewählt. Jedes weitere Amt wird nur
|
||||
// von den aktuellen Inhabern des unmittelbar vorherigen Amttyps
|
||||
// gewählt (z. B. Amt 2 von Inhabern von Amt 1).
|
||||
const heldOffices = await PoliticalOffice.findAll({
|
||||
where: { characterId: character.id },
|
||||
attributes: ['officeTypeId']
|
||||
});
|
||||
const heldOfficeTypeIds = new Set(heldOffices.map((office) => Number(office.officeTypeId)));
|
||||
const rows = await sequelize.query(
|
||||
FalukantService.RECURSIVE_REGION_SEARCH,
|
||||
{
|
||||
@@ -6983,37 +6994,42 @@ class FalukantService extends BaseService {
|
||||
]
|
||||
});
|
||||
|
||||
return rawElections.map(election => {
|
||||
const e = election.get({ plain: true });
|
||||
return rawElections
|
||||
.filter((election) => {
|
||||
const officeTypeId = Number(election.officeTypeId);
|
||||
return officeTypeId === 1 || heldOfficeTypeIds.has(officeTypeId - 1);
|
||||
})
|
||||
.map(election => {
|
||||
const e = election.get({ plain: true });
|
||||
|
||||
const voted = Array.isArray(e.votes) && e.votes.length > 0;
|
||||
const reducedCandidates = (e.candidates || []).map(cand => {
|
||||
const ch = cand.character || {};
|
||||
const firstname = ch.definedFirstName?.name || '';
|
||||
const lastname = ch.definedLastName?.name || '';
|
||||
return {
|
||||
id: cand.id,
|
||||
title: ch.nobleTitle?.labelTr || null,
|
||||
name: `${firstname} ${lastname}`.trim(),
|
||||
age: calcAge(ch.birthdate),
|
||||
gender: ch.gender
|
||||
};
|
||||
});
|
||||
|
||||
const voted = Array.isArray(e.votes) && e.votes.length > 0;
|
||||
const reducedCandidates = (e.candidates || []).map(cand => {
|
||||
const ch = cand.character || {};
|
||||
const firstname = ch.definedFirstName?.name || '';
|
||||
const lastname = ch.definedLastName?.name || '';
|
||||
return {
|
||||
id: cand.id,
|
||||
title: ch.nobleTitle?.labelTr || null,
|
||||
name: `${firstname} ${lastname}`.trim(),
|
||||
age: calcAge(ch.birthdate),
|
||||
gender: ch.gender
|
||||
id: e.id,
|
||||
officeType: { name: e.officeType.name },
|
||||
region: {
|
||||
name: e.region.name,
|
||||
regionType: { labelTr: e.region.regionType.labelTr }
|
||||
},
|
||||
date: e.date,
|
||||
postsToFill: e.postsToFill,
|
||||
candidates: reducedCandidates,
|
||||
voted: voted,
|
||||
votedFor: voted ? e.votes.map(vote => { return vote.candidateId }) : null,
|
||||
};
|
||||
});
|
||||
|
||||
return {
|
||||
id: e.id,
|
||||
officeType: { name: e.officeType.name },
|
||||
region: {
|
||||
name: e.region.name,
|
||||
regionType: { labelTr: e.region.regionType.labelTr }
|
||||
},
|
||||
date: e.date,
|
||||
postsToFill: e.postsToFill,
|
||||
candidates: reducedCandidates,
|
||||
voted: voted,
|
||||
votedFor: voted ? e.votes.map(vote => { return vote.candidateId }) : null,
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
async vote(hashedUserId, votes) {
|
||||
|
||||
Reference in New Issue
Block a user