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,
|
model: ChurchOfficeRequirement,
|
||||||
as: 'requirements',
|
as: 'requirements',
|
||||||
required: false
|
required: false,
|
||||||
|
attributes: ['id', 'officeTypeId', 'prerequisiteOfficeTypeId']
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
order: [['hierarchyLevel', 'ASC']]
|
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 = [];
|
const availablePositions = [];
|
||||||
|
|
||||||
for (const officeType of officeTypes) {
|
for (const officeType of officeTypes) {
|
||||||
// Prüfe Voraussetzungen: Hat der User bereits das erforderliche niedrigere Amt?
|
// Prüfe Voraussetzungen: Hat der User bereits das erforderliche niedrigere Amt?
|
||||||
const requirement = officeType.requirements?.[0];
|
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
|
// Prüfe ob der User das erforderliche Amt innehat
|
||||||
if (!heldOfficeTypeIds.includes(requirement.prerequisiteOfficeTypeId)) {
|
if (!heldOfficeTypeIds.includes(prerequisiteId)) {
|
||||||
continue; // Voraussetzung nicht erfüllt
|
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
|
// Wenn prerequisiteOfficeTypeId === null, dann keine Voraussetzung = Einstiegsposition, OK
|
||||||
} else if (heldOfficeTypeIds.length === 0) {
|
} else {
|
||||||
// Wenn keine Voraussetzung definiert ist, aber User hat noch kein Amt, nur Einstiegspositionen zeigen
|
// Wenn keine Voraussetzung in der DB definiert ist, bedeutet das:
|
||||||
if (officeType.hierarchyLevel > 0) {
|
// - Entweder ist es eine Einstiegsposition (hierarchyLevel 0)
|
||||||
continue;
|
// - 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