Update supervisorId handling in ChurchApplication and FalukantService: Allow supervisorId to be null for entry-level positions, enhancing flexibility in application processing. Improve prerequisite office type updates in initializeFalukantTypes for better data integrity.
This commit is contained in:
@@ -5282,44 +5282,49 @@ class FalukantService extends BaseService {
|
||||
throw new Error('No available seats');
|
||||
}
|
||||
|
||||
// Finde Supervisor
|
||||
const higherOfficeTypeIds = await ChurchOfficeType.findAll({
|
||||
where: {
|
||||
hierarchyLevel: { [Op.gt]: officeType.hierarchyLevel }
|
||||
},
|
||||
attributes: ['id']
|
||||
}).then(types => types.map(t => t.id));
|
||||
|
||||
if (higherOfficeTypeIds.length === 0) {
|
||||
throw new Error('No supervisor office type found');
|
||||
}
|
||||
|
||||
const supervisorOffice = await ChurchOffice.findOne({
|
||||
where: {
|
||||
regionId: regionId,
|
||||
officeTypeId: { [Op.in]: higherOfficeTypeIds }
|
||||
},
|
||||
include: [
|
||||
{
|
||||
model: ChurchOfficeType,
|
||||
as: 'type',
|
||||
attributes: ['hierarchyLevel']
|
||||
// Finde Supervisor (nur wenn es nicht die niedrigste Position ist)
|
||||
let supervisorId = null;
|
||||
if (officeType.hierarchyLevel > 0) {
|
||||
const higherOfficeTypeIds = await ChurchOfficeType.findAll({
|
||||
where: {
|
||||
hierarchyLevel: { [Op.gt]: officeType.hierarchyLevel }
|
||||
},
|
||||
{
|
||||
model: FalukantCharacter,
|
||||
as: 'holder',
|
||||
attributes: ['id']
|
||||
}
|
||||
],
|
||||
order: [
|
||||
[{ model: ChurchOfficeType, as: 'type' }, 'hierarchyLevel', 'ASC']
|
||||
],
|
||||
limit: 1
|
||||
});
|
||||
attributes: ['id']
|
||||
}).then(types => types.map(t => t.id));
|
||||
|
||||
if (!supervisorOffice || !supervisorOffice.holder) {
|
||||
throw new Error('No supervisor found');
|
||||
if (higherOfficeTypeIds.length > 0) {
|
||||
const supervisorOffice = await ChurchOffice.findOne({
|
||||
where: {
|
||||
regionId: regionId,
|
||||
officeTypeId: { [Op.in]: higherOfficeTypeIds }
|
||||
},
|
||||
include: [
|
||||
{
|
||||
model: ChurchOfficeType,
|
||||
as: 'type',
|
||||
attributes: ['hierarchyLevel']
|
||||
},
|
||||
{
|
||||
model: FalukantCharacter,
|
||||
as: 'holder',
|
||||
attributes: ['id']
|
||||
}
|
||||
],
|
||||
order: [
|
||||
[{ model: ChurchOfficeType, as: 'type' }, 'hierarchyLevel', 'ASC']
|
||||
],
|
||||
limit: 1
|
||||
});
|
||||
|
||||
if (!supervisorOffice || !supervisorOffice.holder) {
|
||||
throw new Error('No supervisor found for this position');
|
||||
}
|
||||
supervisorId = supervisorOffice.holder.id;
|
||||
} else {
|
||||
throw new Error('No supervisor office type found');
|
||||
}
|
||||
}
|
||||
// Für Einstiegspositionen (hierarchyLevel 0) ist kein Supervisor erforderlich
|
||||
|
||||
// Prüfe ob bereits eine Bewerbung existiert
|
||||
const existingApplication = await ChurchApplication.findOne({
|
||||
@@ -5340,7 +5345,7 @@ class FalukantService extends BaseService {
|
||||
officeTypeId: officeTypeId,
|
||||
characterId: character.id,
|
||||
regionId: regionId,
|
||||
supervisorId: supervisorOffice.holder.id,
|
||||
supervisorId: supervisorId, // Kann null sein für Einstiegspositionen
|
||||
status: 'pending'
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user