휴가 수정완
Some checks failed
LocalNet_front/pipeline/head There was a failure building this commit

This commit is contained in:
dyhj625 2025-03-11 16:00:12 +09:00
parent a3ea106265
commit 69fb0669be

View File

@ -325,51 +325,66 @@ const filteredReceivedVacations = computed(() => {
//
async function saveVacationChanges() {
if (!hasChanges.value) return;
const selectedDatesArray = Array.from(selectedDates.value);
const vacationChangesByYear = selectedDatesArray.reduce((acc, [date, type]) => {
const year = date.split("-")[0]; // YYYY-MM-DD YYYY
if (!acc[year]) acc[year] = { add: [], delete: [] };
//
const vacationChanges = selectedDatesArray.reduce((acc, [date, type]) => {
if (type !== "delete") {
acc[year].add.push({ date, type });
acc.add.push({ date, type });
} else {
acc[year].delete.push(date);
acc.delete.push(date);
}
return acc;
}, {});
}, { add: [], delete: [] });
try {
for (const year of Object.keys(vacationChangesByYear)) {
const vacationsToAdd = vacationChangesByYear[year].add;
// id
const vacationsToDeleteForYear = myVacations.value
.filter(vac => {
// ID
const allYears = new Set(vacationChanges.delete.map(date => date.split("-")[0]));
let vacationIdsToDelete = [];
for (const year of allYears) {
await fetchVacationHistory(year); //
const vacationsToDelete = myVacations.value.filter(vac => {
if (!vac.date) return false;
const vacDate = vac.date.split("T")[0];
return vacationChangesByYear[year].delete.includes(vacDate);
return vacationChanges.delete.includes(vacDate);
});
const vacationIdsToDelete = vacationsToDeleteForYear.map(vac => vac.id);
if (vacationsToAdd.length > 0 || vacationIdsToDelete.length > 0) {
vacationIdsToDelete.push(...vacationsToDelete.map(vac => vac.id));
}
if (vacationChanges.add.length > 0 || vacationIdsToDelete.length > 0) {
const response = await axios.post("vacation/batchUpdate", {
add: vacationsToAdd,
add: vacationChanges.add,
delete: vacationIdsToDelete,
});
if (response.data && response.data.status === "OK") {
toastStore.onToast(`휴가 변경 사항이 저장되었습니다.`, 's');
// : myVacations ID
// ID `myVacations.value`
myVacations.value = myVacations.value.filter(vac => !vacationIdsToDelete.includes(vac.id));
//
// ( )
const yearsToUpdate = new Set(
[...vacationChanges.add.map(v => v.date.split("-")[0]),
...vacationChanges.delete.map(v => v.split("-")[0])]
);
for (const year of yearsToUpdate) {
const updatedVacations = await fetchVacationHistory(year);
if (updatedVacations) {
myVacations.value = updatedVacations; //
myVacations.value = [...myVacations.value, ...updatedVacations.filter(newVac =>
!myVacations.value.some(oldVac => oldVac.id === newVac.id)
)];
}
}
} else {
toastStore.onToast(`휴가 변경 중 오류가 발생했습니다.`, 'e');
}
}
}
await fetchRemainingVacation();
selectedDates.value.clear();
updateCalendarEvents();
//
//
const currentDate = fullCalendarRef.value.getApi().getDate();
await loadCalendarData(currentDate.getFullYear(), currentDate.getMonth() + 1);
} catch (error) {
@ -377,7 +392,6 @@ async function saveVacationChanges() {
toastStore.onToast('휴가 저장 요청에 실패했습니다.', 'e');
}
}
/* 휴가 조회 */
//
async function fetchVacationHistory(year) {