1 |
7495b9eb
|
plundrichov
|
// ******************** GET DATA APP getCurrentProfile, [userName, setUserName] ********************
|
2 |
|
|
|
3 |
|
|
export const getCurrentProfile = async () => {
|
4 |
|
|
|
5 |
|
|
try {
|
6 |
|
|
const response = await fetch(
|
7 |
|
|
'http://devcz.yoso.fi:8090/ymanager/users/current/profile', {
|
8 |
|
|
headers: {
|
9 |
|
|
Authorization: 1
|
10 |
|
|
}
|
11 |
|
|
}
|
12 |
|
|
);
|
13 |
|
|
|
14 |
|
|
if (response.ok) {
|
15 |
|
|
const data = await response.json();
|
16 |
|
|
return {
|
17 |
|
|
name: data.firstName + ' ' + data.lastName,
|
18 |
|
|
role: data.role,
|
19 |
|
|
id: data.id,
|
20 |
|
|
holiday: data.vacationCount,
|
21 |
|
|
sickday: data.sickDayCount
|
22 |
|
|
}
|
23 |
|
|
} else {
|
24 |
|
|
if(response.status === 400) {
|
25 |
|
|
alert('error 400 GET DATA APP (getCurrentProfile)')
|
26 |
|
|
}
|
27 |
|
|
else if (response.status === 500) {
|
28 |
|
|
alert ('error 500 GET DATA APP (getCurrentProfile)')
|
29 |
|
|
}
|
30 |
|
|
else {
|
31 |
|
|
alert('error GET DATA APP (getCurrentProfile)')
|
32 |
|
|
}
|
33 |
|
|
}
|
34 |
|
|
|
35 |
|
|
} catch (e) {
|
36 |
|
|
alert('error catch GET DATA APP (getCurrentProfile)')
|
37 |
|
|
}
|
38 |
|
|
}
|
39 |
|
|
|
40 |
|
|
// ******************** LOAD DATA to CALENDAR - EMPLOYEE ********************
|
41 |
|
|
export const getUserCalendar = async (userName, fromDate ) => {
|
42 |
|
|
try {
|
43 |
|
|
const response = await fetch(
|
44 |
|
|
`http://devcz.yoso.fi:8090/ymanager/user/${userName.id}/calendar?from=${fromDate}&status=ACCEPTED&status=REJECTED`, {
|
45 |
|
|
headers: {
|
46 |
|
|
'Accept': 'application/json',
|
47 |
|
|
Authorization: 6
|
48 |
|
|
},
|
49 |
|
|
method: 'GET',
|
50 |
|
|
}
|
51 |
|
|
);
|
52 |
|
|
|
53 |
|
|
if (response.ok) {
|
54 |
|
|
const data = await response.json();
|
55 |
|
|
|
56 |
|
|
return data.filter(day => {
|
57 |
|
|
return day.status !== 'PENDING'
|
58 |
|
|
}).map(day => {
|
59 |
|
|
|
60 |
|
|
const newDate = day.date.split("/").join("-");
|
61 |
|
|
|
62 |
|
|
return ({
|
63 |
|
|
title: userName.name,
|
64 |
|
|
start: newDate,
|
65 |
|
|
backgroundColor: day.status === 'REJECTED' ? 'red' : 'green'
|
66 |
|
|
})
|
67 |
|
|
})
|
68 |
|
|
} else {
|
69 |
|
|
if(response.status === 400) {
|
70 |
|
|
alert('error 400 LOADING DATA (CALENDAR, EMPLOYEE)')
|
71 |
|
|
}
|
72 |
|
|
else if (response.status === 500) {
|
73 |
|
|
alert ('error 500 LOADING DATA (CALENDAR, EMPLOYEE)')
|
74 |
|
|
}
|
75 |
|
|
else {
|
76 |
|
|
alert('error LOADING DATA (CALENDAR, EMPLOYEE)')
|
77 |
|
|
}
|
78 |
|
|
}
|
79 |
|
|
} catch (e) {
|
80 |
|
|
alert('error catch LOADING DATA (CALENDAR, EMPLOYEE)')
|
81 |
|
|
}
|
82 |
|
|
}
|
83 |
|
|
|
84 |
|
|
// ******************** LOAD DATA to CALENDAR - EMPLOYER ********************
|
85 |
|
|
export const getAdminCalendar = async () => {
|
86 |
|
|
try {
|
87 |
|
|
const response = await fetch(
|
88 |
|
|
'http://devcz.yoso.fi:8090/ymanager/users/requests/vacation?status=ACCEPTED', {
|
89 |
|
|
headers: {
|
90 |
|
|
'Accept': 'application/json',
|
91 |
|
|
Authorization: 1
|
92 |
|
|
},
|
93 |
|
|
method: 'GET',
|
94 |
|
|
}
|
95 |
|
|
);
|
96 |
|
|
|
97 |
|
|
if (response.ok) {
|
98 |
|
|
const data = await response.json();
|
99 |
|
|
|
100 |
|
|
return data.map(day => {
|
101 |
|
|
|
102 |
|
|
const newDate = day.date.split("/").join("-");
|
103 |
|
|
|
104 |
|
|
return ( {
|
105 |
|
|
title: day.firstName + ' ' + day.lastName,
|
106 |
|
|
start: newDate
|
107 |
|
|
})
|
108 |
|
|
})
|
109 |
|
|
} else {
|
110 |
|
|
if(response.status === 400) {
|
111 |
|
|
alert('error 400 LOADING DATA (CALENDAR, EMPLOYER)')
|
112 |
|
|
}
|
113 |
|
|
else if (response.status === 500) {
|
114 |
|
|
alert ('error 500 LOADING DATA (CALENDAR, EMPLOYER))')
|
115 |
|
|
}
|
116 |
|
|
else {
|
117 |
|
|
alert('error LOADING DATA (CALENDAR, EMPLOYER)')
|
118 |
|
|
}
|
119 |
|
|
}
|
120 |
|
|
} catch (e) {
|
121 |
|
|
alert('error catch LOADING DATA (CALENDAR, EMPLOYER)')
|
122 |
|
|
}
|
123 |
|
|
}
|
124 |
|
|
|
125 |
|
|
// ******************** ADD EVENT to CALENDAR - EMPLOYEE ********************
|
126 |
|
|
export const addEvent = async (e) => {
|
127 |
|
|
e.preventDefault();
|
128 |
|
|
|
129 |
|
|
// setting an object
|
130 |
|
|
const newDate = whatDate.split("-").join("/");
|
131 |
|
|
|
132 |
|
|
try {
|
133 |
|
|
// send accepted request to server
|
134 |
|
|
const response = await fetch('http://devcz.yoso.fi:8090/ymanager/user/calendar/create', {
|
135 |
|
|
headers: {
|
136 |
|
|
Authorization: 6,
|
137 |
|
|
'Content-Type': 'application/json',
|
138 |
|
|
},
|
139 |
|
|
method: 'POST',
|
140 |
|
|
// object which is sent to server
|
141 |
|
|
body: JSON.stringify({
|
142 |
|
|
type: typeRadio === 'sickday' ? 'SICK_DAY' : 'VACATION',
|
143 |
|
|
date: newDate,
|
144 |
|
|
from: typeRadio === 'sickday' ? null : "00:00",
|
145 |
|
|
to: typeRadio === 'sickday' ? null : moment().startOf('day').add(whatTime, "hours").format("hh:mm"),
|
146 |
|
|
}),
|
147 |
|
|
});
|
148 |
|
|
if (response.ok) {
|
149 |
|
|
|
150 |
|
|
const response = await fetch(
|
151 |
|
|
'http://devcz.yoso.fi:8090/ymanager/users/requests/vacation?status=PENDING', {
|
152 |
|
|
headers: {
|
153 |
|
|
Authorization: 1
|
154 |
|
|
},
|
155 |
|
|
}
|
156 |
|
|
|
157 |
|
|
);
|
158 |
|
|
const data = await response.json();
|
159 |
|
|
|
160 |
|
|
return data.map(request => {
|
161 |
|
|
const a = request.date;
|
162 |
|
|
const b = [a.slice(0, 4), "-", a.slice(5, 7), "-", a.slice(8, 10)].join('');
|
163 |
|
|
|
164 |
|
|
return (
|
165 |
|
|
{
|
166 |
|
|
title: request.firstName + ' ' + request.lastName,
|
167 |
|
|
id: request.id,
|
168 |
|
|
type: request.type,
|
169 |
|
|
start: b,
|
170 |
|
|
end: null,
|
171 |
|
|
status: request.status
|
172 |
|
|
})
|
173 |
|
|
})
|
174 |
|
|
|
175 |
|
|
} else {
|
176 |
|
|
|
177 |
|
|
if(response.status === 400) {
|
178 |
|
|
alert('error 400 ADD EVENT - EMPLOYEE')
|
179 |
|
|
}
|
180 |
|
|
else if (response.status === 500) {
|
181 |
|
|
alert ('error 500 ADD EVENT - EMPLOYEE')
|
182 |
|
|
}
|
183 |
|
|
else {
|
184 |
|
|
alert('error ADD EVENT - EMPLOYEE')
|
185 |
|
|
}
|
186 |
|
|
|
187 |
|
|
}
|
188 |
|
|
} catch (e) {
|
189 |
|
|
alert('error catch ADD EVENT - EMPLOYEE')
|
190 |
|
|
}
|
191 |
|
|
|
192 |
|
|
setOpen(false)}
|
193 |
|
|
|
194 |
|
|
//
|