Enhance logging and validation in getAvailableChurchPositions: Add detailed console logs for office type requirements and user qualifications, improving debugging and ensuring correct handling of prerequisite office types.
This commit is contained in:
@@ -4991,28 +4991,55 @@ class FalukantService extends BaseService {
|
||||
{
|
||||
model: ChurchOfficeRequirement,
|
||||
as: 'requirements',
|
||||
required: false
|
||||
required: false,
|
||||
attributes: ['id', 'officeTypeId', 'prerequisiteOfficeTypeId']
|
||||
}
|
||||
],
|
||||
order: [['hierarchyLevel', 'ASC']]
|
||||
});
|
||||
|
||||
console.log(`[getAvailableChurchPositions] Loaded ${officeTypes.length} office types. Held offices:`, heldOfficeTypeIds);
|
||||
// Debug: Zeige alle geladenen Voraussetzungen
|
||||
officeTypes.forEach(ot => {
|
||||
if (ot.requirements && ot.requirements.length > 0) {
|
||||
console.log(` - ${ot.name} (id=${ot.id}): prerequisiteOfficeTypeId=${ot.requirements[0].prerequisiteOfficeTypeId}`);
|
||||
} else {
|
||||
console.log(` - ${ot.name} (id=${ot.id}): NO REQUIREMENT DEFINED`);
|
||||
}
|
||||
});
|
||||
|
||||
const availablePositions = [];
|
||||
|
||||
for (const officeType of officeTypes) {
|
||||
// Prüfe Voraussetzungen: Hat der User bereits das erforderliche niedrigere Amt?
|
||||
const requirement = officeType.requirements?.[0];
|
||||
if (requirement && requirement.prerequisiteOfficeTypeId) {
|
||||
|
||||
console.log(`[getAvailableChurchPositions] Checking ${officeType.name} (id=${officeType.id}, hierarchyLevel=${officeType.hierarchyLevel}):`, {
|
||||
hasRequirement: !!requirement,
|
||||
prerequisiteOfficeTypeId: requirement?.prerequisiteOfficeTypeId,
|
||||
heldOfficeTypeIds: heldOfficeTypeIds
|
||||
});
|
||||
|
||||
// Prüfe Voraussetzungen
|
||||
if (requirement) {
|
||||
// Wenn eine Voraussetzung definiert ist
|
||||
const prerequisiteId = requirement.prerequisiteOfficeTypeId;
|
||||
if (prerequisiteId !== null && prerequisiteId !== undefined) {
|
||||
// Prüfe ob der User das erforderliche Amt innehat
|
||||
if (!heldOfficeTypeIds.includes(requirement.prerequisiteOfficeTypeId)) {
|
||||
continue; // Voraussetzung nicht erfüllt
|
||||
if (!heldOfficeTypeIds.includes(prerequisiteId)) {
|
||||
console.log(`[getAvailableChurchPositions] Skipping ${officeType.name}: User doesn't have prerequisite office ${prerequisiteId}. Held offices:`, heldOfficeTypeIds);
|
||||
continue; // Voraussetzung nicht erfüllt - User hat das erforderliche Amt nicht
|
||||
}
|
||||
} else if (requirement && requirement.prerequisiteOfficeTypeId === null) {
|
||||
// Keine Voraussetzung = Einstiegsposition, OK
|
||||
} else if (heldOfficeTypeIds.length === 0) {
|
||||
// Wenn keine Voraussetzung definiert ist, aber User hat noch kein Amt, nur Einstiegspositionen zeigen
|
||||
if (officeType.hierarchyLevel > 0) {
|
||||
continue;
|
||||
}
|
||||
// Wenn prerequisiteOfficeTypeId === null, dann keine Voraussetzung = Einstiegsposition, OK
|
||||
} else {
|
||||
// Wenn keine Voraussetzung in der DB definiert ist, bedeutet das:
|
||||
// - Entweder ist es eine Einstiegsposition (hierarchyLevel 0)
|
||||
// - Oder die Voraussetzung wurde noch nicht initialisiert
|
||||
// Sicherheitshalber: Nur Einstiegspositionen ohne Voraussetzung erlauben
|
||||
if (officeType.hierarchyLevel !== 0) {
|
||||
console.log(`[getAvailableChurchPositions] Skipping ${officeType.name}: No requirement defined in DB and hierarchyLevel > 0 (${officeType.hierarchyLevel}). This might be a configuration issue.`);
|
||||
continue; // Keine Voraussetzung definiert für höheres Amt = vermutlich Konfigurationsfehler
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user