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:
@@ -23,8 +23,8 @@ ChurchApplication.init({
|
|||||||
},
|
},
|
||||||
supervisorId: {
|
supervisorId: {
|
||||||
type: DataTypes.INTEGER,
|
type: DataTypes.INTEGER,
|
||||||
allowNull: false,
|
allowNull: true,
|
||||||
comment: 'ID des Vorgesetzten, der über die Bewerbung entscheidet'
|
comment: 'ID des Vorgesetzten, der über die Bewerbung entscheidet (null für Einstiegspositionen ohne Supervisor)'
|
||||||
},
|
},
|
||||||
status: {
|
status: {
|
||||||
type: DataTypes.ENUM('pending', 'approved', 'rejected'),
|
type: DataTypes.ENUM('pending', 'approved', 'rejected'),
|
||||||
|
|||||||
@@ -5282,7 +5282,9 @@ class FalukantService extends BaseService {
|
|||||||
throw new Error('No available seats');
|
throw new Error('No available seats');
|
||||||
}
|
}
|
||||||
|
|
||||||
// Finde Supervisor
|
// Finde Supervisor (nur wenn es nicht die niedrigste Position ist)
|
||||||
|
let supervisorId = null;
|
||||||
|
if (officeType.hierarchyLevel > 0) {
|
||||||
const higherOfficeTypeIds = await ChurchOfficeType.findAll({
|
const higherOfficeTypeIds = await ChurchOfficeType.findAll({
|
||||||
where: {
|
where: {
|
||||||
hierarchyLevel: { [Op.gt]: officeType.hierarchyLevel }
|
hierarchyLevel: { [Op.gt]: officeType.hierarchyLevel }
|
||||||
@@ -5290,10 +5292,7 @@ class FalukantService extends BaseService {
|
|||||||
attributes: ['id']
|
attributes: ['id']
|
||||||
}).then(types => types.map(t => t.id));
|
}).then(types => types.map(t => t.id));
|
||||||
|
|
||||||
if (higherOfficeTypeIds.length === 0) {
|
if (higherOfficeTypeIds.length > 0) {
|
||||||
throw new Error('No supervisor office type found');
|
|
||||||
}
|
|
||||||
|
|
||||||
const supervisorOffice = await ChurchOffice.findOne({
|
const supervisorOffice = await ChurchOffice.findOne({
|
||||||
where: {
|
where: {
|
||||||
regionId: regionId,
|
regionId: regionId,
|
||||||
@@ -5318,8 +5317,14 @@ class FalukantService extends BaseService {
|
|||||||
});
|
});
|
||||||
|
|
||||||
if (!supervisorOffice || !supervisorOffice.holder) {
|
if (!supervisorOffice || !supervisorOffice.holder) {
|
||||||
throw new Error('No supervisor found');
|
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
|
// Prüfe ob bereits eine Bewerbung existiert
|
||||||
const existingApplication = await ChurchApplication.findOne({
|
const existingApplication = await ChurchApplication.findOne({
|
||||||
@@ -5340,7 +5345,7 @@ class FalukantService extends BaseService {
|
|||||||
officeTypeId: officeTypeId,
|
officeTypeId: officeTypeId,
|
||||||
characterId: character.id,
|
characterId: character.id,
|
||||||
regionId: regionId,
|
regionId: regionId,
|
||||||
supervisorId: supervisorOffice.holder.id,
|
supervisorId: supervisorId, // Kann null sein für Einstiegspositionen
|
||||||
status: 'pending'
|
status: 'pending'
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -1139,7 +1139,17 @@ export const initializeChurchOfficePrerequisites = async () => {
|
|||||||
prerequisiteOfficeTypeId: prerequisiteOfficeTypeId
|
prerequisiteOfficeTypeId: prerequisiteOfficeTypeId
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
if (wasCreated) created++; else existing++;
|
if (wasCreated) {
|
||||||
|
created++;
|
||||||
|
} else {
|
||||||
|
// Aktualisiere, falls sich die Voraussetzung geändert hat
|
||||||
|
if (record.prerequisiteOfficeTypeId !== prerequisiteOfficeTypeId) {
|
||||||
|
await record.update({ prerequisiteOfficeTypeId: prerequisiteOfficeTypeId });
|
||||||
|
created++; // Zähle als Update
|
||||||
|
} else {
|
||||||
|
existing++;
|
||||||
|
}
|
||||||
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
if (falukantDebug) console.error('[Falukant] ChurchOfficePrereq Fehler', { officeId: office?.id, error: e.message });
|
if (falukantDebug) console.error('[Falukant] ChurchOfficePrereq Fehler', { officeId: office?.id, error: e.message });
|
||||||
throw e;
|
throw e;
|
||||||
|
|||||||
Reference in New Issue
Block a user