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