Add profile routes to backend and frontend; implement user state handling for holidays and workdays, and update UI components for profile settings
This commit is contained in:
@@ -539,21 +539,58 @@ class WorklogRepository {
|
||||
* @param {Date} endDate - End-Datum
|
||||
* @returns {Promise<Array>} Array von Holiday-Einträgen mit Datum und Stunden
|
||||
*/
|
||||
async getHolidaysInDateRange(startDate, endDate) {
|
||||
const { Holiday } = database.getModels();
|
||||
async getHolidaysInDateRange(startDate, endDate, userId = null) {
|
||||
const { Holiday, State, User } = database.getModels();
|
||||
|
||||
try {
|
||||
// Hole User-Bundesland (falls userId angegeben)
|
||||
let userStateId = null;
|
||||
if (userId) {
|
||||
const user = await User.findByPk(userId, {
|
||||
attributes: ['state_id'],
|
||||
raw: true
|
||||
});
|
||||
userStateId = user?.state_id;
|
||||
}
|
||||
|
||||
const holidays = await Holiday.findAll({
|
||||
where: {
|
||||
date: {
|
||||
[Op.between]: [startDate, endDate]
|
||||
}
|
||||
},
|
||||
raw: true,
|
||||
include: [
|
||||
{
|
||||
model: State,
|
||||
as: 'states',
|
||||
attributes: ['id'],
|
||||
through: { attributes: [] },
|
||||
required: false
|
||||
}
|
||||
],
|
||||
order: [['date', 'ASC']]
|
||||
});
|
||||
|
||||
return holidays;
|
||||
// Filtere nach User-Bundesland (falls userId angegeben)
|
||||
if (userId && userStateId) {
|
||||
return holidays.filter(h => {
|
||||
const holidayStates = h.states || [];
|
||||
const isFederal = holidayStates.length === 0;
|
||||
const appliesToUser = isFederal || holidayStates.some(s => s.id === userStateId);
|
||||
return appliesToUser;
|
||||
}).map(h => ({
|
||||
date: h.date,
|
||||
hours: h.hours,
|
||||
description: h.description
|
||||
}));
|
||||
}
|
||||
|
||||
// Ohne userId: Alle Feiertage zurückgeben
|
||||
return holidays.map(h => ({
|
||||
date: h.date,
|
||||
hours: h.hours,
|
||||
description: h.description
|
||||
}));
|
||||
} catch (error) {
|
||||
console.error('Fehler beim Abrufen der Feiertage:', error);
|
||||
return [];
|
||||
|
||||
Reference in New Issue
Block a user