Revize ebfe6347
Přidáno uživatelem plundrichov před více než 4 roky(ů)
client/src/App.js | ||
---|---|---|
16 | 16 |
|
17 | 17 |
useEffect(() => { |
18 | 18 |
api_fetch.getCurrentProfile().then(currentProfile => { |
19 |
setUserName(currentProfile); |
|
19 |
setUserName(currentProfile);
|
|
20 | 20 |
}).catch(reason => { |
21 |
alert(reason) |
|
21 |
alert(reason)
|
|
22 | 22 |
}); |
23 | 23 |
}, []); |
24 | 24 |
|
25 |
|
|
26 | 25 |
const [userName, setUserName] = useState([ |
27 |
{ |
|
28 |
name: 'Golstoj Hyhrenciv'
|
|
29 |
} |
|
30 |
]); |
|
26 |
{ name: 'Golstoj Hyhrenciv' }
|
|
27 |
]);
|
|
28 |
|
|
29 |
|
|
31 | 30 |
|
32 | 31 |
return ( |
33 | 32 |
<BrowserRouter> |
... | ... | |
35 | 34 |
<Nav userName={userName} /> |
36 | 35 |
<div className="container"> |
37 | 36 |
<Switch> |
38 |
<Route path="/" exact component={() => <Home userName={userName}/>}/> |
|
39 |
|
|
40 |
<Route path="/setting">{userName.role === 'EMPLOYER' ? <Setting/>: |
|
41 |
<div className="permissionText column"> |
|
42 |
<p>You don't have permission to access on this server.</p> |
|
43 |
</div>}</Route> |
|
44 |
|
|
37 |
<Route path="/" exact component={() => <Home userName={userName} setUserName={setUserName}/>}/> |
|
38 |
<Route path="/setting"> |
|
39 |
{userName.role === 'EMPLOYER' |
|
40 |
? |
|
41 |
<Setting/> |
|
42 |
: |
|
43 |
<div className="permissionText column"> |
|
44 |
<p>You don't have permission to access on this server.</p> |
|
45 |
</div> |
|
46 |
} |
|
47 |
</Route> |
|
45 | 48 |
<Route path="/logout"><LogOut/></Route> |
46 | 49 |
<Route path="/login"><Login/></Route> |
47 | 50 |
</Switch> |
... | ... | |
61 | 64 |
setUser(dataUserRequest); |
62 | 65 |
}, []); |
63 | 66 |
|
67 |
// OverviewAdmin state |
|
68 |
const [employees, setEmployees] = useState([ |
|
69 |
{ |
|
70 |
name: 'Sadam', |
|
71 |
id: 0, |
|
72 |
sickday: 10, |
|
73 |
holiday: 10, |
|
74 |
takenSickday: 2 |
|
75 |
} |
|
76 |
]); |
|
77 |
|
|
64 | 78 |
function getDataUserRequest() { |
65 | 79 |
return ([]); |
66 | 80 |
} |
67 | 81 |
|
68 | 82 |
return ( |
69 |
<div className="container"> |
|
70 |
<div className="main-content"> |
|
71 |
{props.userName.role === 'EMPLOYER' ? <UpcomingRequests userRequest={userRequest} setUser={setUser} acceptedRequest={acceptedRequest} setRequest={setRequest} /> : <YourRequests userRequest={userRequest} setUser={setUser} acceptedRequest={acceptedRequest} setRequest={setRequest} userName={props.userName}/>} |
|
72 |
<Calendar setUser={setUser} userRequest={userRequest} acceptedRequest={acceptedRequest} setRequest={setRequest} userName={props.userName}/> |
|
83 |
<div className="container"> |
|
84 |
<div className="main-content"> |
|
85 |
{props.userName.role === 'EMPLOYER' |
|
86 |
? |
|
87 |
<UpcomingRequests userRequest={userRequest} setUser={setUser} acceptedRequest={acceptedRequest} setRequest={setRequest} setEmployees={setEmployees}/> |
|
88 |
: |
|
89 |
<YourRequests userRequest={userRequest} setUser={setUser} acceptedRequest={acceptedRequest} setRequest={setRequest} userName={props.userName}/> |
|
90 |
} |
|
91 |
<Calendar setUser={setUser} userRequest={userRequest} acceptedRequest={acceptedRequest} setRequest={setRequest} userName={props.userName} setEmployees={setEmployees} setUserName={props.setUserName}/> |
|
92 |
</div> |
|
93 |
{props.userName.role === 'EMPLOYER' |
|
94 |
? |
|
95 |
<OverviewAdmin employees={employees} setEmployees={setEmployees} /> |
|
96 |
: |
|
97 |
<Overview userName={props.userName} employees={employees} /> |
|
98 |
} |
|
73 | 99 |
</div> |
74 |
{props.userName.role === 'EMPLOYER' ? <OverviewAdmin /> : <Overview userName={props.userName} />} |
|
75 |
</div> |
|
76 | 100 |
) |
77 | 101 |
}; |
78 | 102 |
|
client/src/Calendar.js | ||
---|---|---|
54 | 54 |
const addEvent = async (e) => { |
55 | 55 |
e.preventDefault(); |
56 | 56 |
|
57 |
try { |
|
57 | 58 |
// setting an object |
58 | 59 |
const newDate = whatDate.split("-").join("/"); |
59 | 60 |
|
... | ... | |
64 | 65 |
to: typeRadio === 'sickday' ? null : moment().startOf('day').add(whatTime, "hours").format("hh:mm"), |
65 | 66 |
} |
66 | 67 |
|
67 |
api_fetch.addEventApi(dataAddEventEmployee).catch(reason => { |
|
68 |
alert(reason) |
|
69 |
}); |
|
68 |
await api_fetch.addEventApi(dataAddEventEmployee); |
|
69 |
if (typeRadio === 'holiday') { |
|
70 |
props.setUserName({ |
|
71 |
...props.userName, |
|
72 |
holiday: props.userName.holiday - whatTime |
|
73 |
}) |
|
74 |
} else if (typeRadio === 'sickday') { |
|
75 |
props.setUserName({ |
|
76 |
...props.userName, |
|
77 |
takenSickday: props.userName.takenSickday + 1 |
|
78 |
}) |
|
79 |
} |
|
70 | 80 |
|
71 | 81 |
setOpen(false) |
82 |
} catch (e) { |
|
83 |
alert(e) |
|
72 | 84 |
} |
73 |
|
|
85 |
} |
|
74 | 86 |
// ********************* ADD EVENT ADMIN - EMPLOYER ************************** |
75 | 87 |
|
76 | 88 |
const addEventAdmin = async (e) => { |
... | ... | |
94 | 106 |
//concat new request to current ones |
95 | 107 |
props.setRequest((acceptedRequest) => acceptedRequest.concat(userProps)) |
96 | 108 |
}).catch(reason => { |
97 |
alert(reason) |
|
109 |
alert(reason)
|
|
98 | 110 |
}); |
99 | 111 |
|
100 | 112 |
setOpen(false) |
113 |
|
|
114 |
api_fetch.getUsersOverview().then(usersOverview => { |
|
115 |
props.setEmployees(usersOverview); |
|
116 |
}).catch(reason => { |
|
117 |
alert(reason) |
|
118 |
}); |
|
101 | 119 |
} |
102 | 120 |
|
103 |
|
|
104 | 121 |
return ( |
105 | 122 |
<div className="calendar"> |
106 | 123 |
|
client/src/Overview.js | ||
---|---|---|
22 | 22 |
</tr> |
23 | 23 |
<tr> |
24 | 24 |
<td>{props.userName.name}</td> |
25 |
<td className="td-center">{props.userName.sickday}</td> |
|
25 |
<td className="td-center">{props.userName.takenSickday + '/' + props.userName.sickday}</td>
|
|
26 | 26 |
<td className="td-center">{props.userName.holiday}</td> |
27 | 27 |
</tr> |
28 | 28 |
</tbody> |
client/src/OverviewAdmin.js | ||
---|---|---|
3 | 3 |
import * as api_fetch from './api' |
4 | 4 |
|
5 | 5 |
|
6 |
const OverviewAdmin = () => { |
|
6 |
const OverviewAdmin = (props) => {
|
|
7 | 7 |
|
8 | 8 |
useEffect(() => { |
9 | 9 |
api_fetch.getUsersOverview().then(usersOverview => { |
10 |
setEmployees(usersOverview); |
|
10 |
props.setEmployees(usersOverview);
|
|
11 | 11 |
}).catch(reason => { |
12 | 12 |
alert(reason) |
13 | 13 |
}); |
14 | 14 |
}, []); |
15 | 15 |
|
16 | 16 |
// states |
17 |
const [employees, setEmployees] = useState([ |
|
18 |
{ |
|
19 |
name: 'Sadam', |
|
20 |
id: 0, |
|
21 |
sickday: 10, |
|
22 |
holiday: 10 |
|
23 |
} |
|
24 |
]); |
|
17 |
// const [employees, setEmployees] = useState([
|
|
18 |
// {
|
|
19 |
// name: 'Sadam',
|
|
20 |
// id: 0,
|
|
21 |
// sickday: 10,
|
|
22 |
// holiday: 10
|
|
23 |
// }
|
|
24 |
// ]);
|
|
25 | 25 |
|
26 | 26 |
const [isEdit, setEdit] = useState(false); |
27 | 27 |
const [editedUserId, setEditedUserId] = useState(); |
... | ... | |
30 | 30 |
|
31 | 31 |
// functions |
32 | 32 |
function changeSickdays(newValue) { |
33 |
const newEmployees = employees.map(employee => { |
|
33 |
const newEmployees = props.employees.map(employee => {
|
|
34 | 34 |
if (editedUserId === employee.id) { |
35 | 35 |
return { |
36 | 36 |
...employee, |
... | ... | |
40 | 40 |
return employee |
41 | 41 |
} |
42 | 42 |
}) |
43 |
setEmployees(newEmployees); |
|
43 |
props.setEmployees(newEmployees);
|
|
44 | 44 |
} |
45 | 45 |
|
46 | 46 |
function changeHoliday(newValue) { |
47 |
const newEmployees = employees.map(employee => { |
|
47 |
const newEmployees = props.employees.map(employee => {
|
|
48 | 48 |
if (editedUserId === employee.id) { |
49 | 49 |
return { |
50 | 50 |
...employee, |
... | ... | |
54 | 54 |
return employee |
55 | 55 |
} |
56 | 56 |
}) |
57 |
setEmployees(newEmployees); |
|
57 |
props.setEmployees(newEmployees);
|
|
58 | 58 |
} |
59 | 59 |
|
60 | 60 |
const submitEdit = async (e) => { |
61 | 61 |
|
62 | 62 |
setEdit(isEdit === true ? false : true); |
63 |
setPrevEdit(employees); |
|
63 |
setPrevEdit(props.employees);
|
|
64 | 64 |
e.preventDefault(); |
65 | 65 |
|
66 |
const found = employees.find(employee => editedUserId === employee.id); |
|
66 |
const found = props.employees.find(employee => editedUserId === employee.id);
|
|
67 | 67 |
const foundPrevEdit = prevEdit.find(employee => editedUserId === employee.id); |
68 | 68 |
|
69 | 69 |
const dataOverviewObject = { |
... | ... | |
79 | 79 |
} |
80 | 80 |
|
81 | 81 |
const cancel = () => { |
82 |
setEmployees(prevEdit) |
|
82 |
props.setEmployees(prevEdit)
|
|
83 | 83 |
setEdit(false) |
84 | 84 |
} |
85 | 85 |
|
... | ... | |
88 | 88 |
const editEmployee = (employeeId, e) => { |
89 | 89 |
setEdit(true) |
90 | 90 |
setEditedUserId(employeeId) |
91 |
setPrevEdit(employees) |
|
91 |
setPrevEdit(props.employees)
|
|
92 | 92 |
|
93 | 93 |
e.preventDefault(); |
94 | 94 |
} |
... | ... | |
112 | 112 |
<th>Holiday</th> |
113 | 113 |
<th></th> |
114 | 114 |
</tr> |
115 |
{employees.map(employee => ( |
|
115 |
{props.employees.map(employee => (
|
|
116 | 116 |
<tr> |
117 |
<td>{employee.name} {editedUserId}</td>
|
|
117 |
<td>{employee.name}</td> |
|
118 | 118 |
{/* SickDays Input */} |
119 | 119 |
<td className="td-center"> |
120 | 120 |
{isEdit === true && editedUserId === employee.id ? ( |
121 | 121 |
<input className="offsInput" type="number" min="0" value={employee.sickday} onChange={(e) => changeSickdays(e.target.value)}/> |
122 | 122 |
) : ( |
123 |
employee.sickday |
|
123 |
employee.takenSickday + '/' + employee.sickday
|
|
124 | 124 |
)} |
125 | 125 |
</td> |
126 | 126 |
{/* Holiday Input */} |
client/src/UpcomingRequests.js | ||
---|---|---|
1 |
import React, { useEffect } from 'react'; |
|
1 |
import React, { useState, useEffect } from 'react';
|
|
2 | 2 |
import './App.css'; |
3 |
import moment from 'moment'; |
|
3 | 4 |
import * as api_fetch from './api' |
4 | 5 |
|
5 | 6 |
function UpcomingRequests(props) { |
... | ... | |
21 | 22 |
{ |
22 | 23 |
title: request.firstName + ' ' + request.lastName, |
23 | 24 |
id: request.id, |
24 |
type: request.type,
|
|
25 |
start: b,
|
|
25 |
type: convertVacationType(request.type),
|
|
26 |
start: moment(b).format("D.M.YYYY"),
|
|
26 | 27 |
end: null, |
27 |
status: request.status |
|
28 |
status: request.status = request.status.toLowerCase()
|
|
28 | 29 |
}) |
29 | 30 |
})) |
30 | 31 |
}).catch(reason => { |
... | ... | |
32 | 33 |
}); |
33 | 34 |
} |
34 | 35 |
|
36 |
function convertVacationType(vacationType) { |
|
37 |
switch (vacationType) { |
|
38 |
case 'SICK_DAY' : |
|
39 |
return 'sickday'; |
|
40 |
case 'HOLIDAY': |
|
41 |
return 'holiday'; |
|
42 |
} |
|
43 |
} |
|
44 |
|
|
35 | 45 |
|
36 | 46 |
|
37 | 47 |
// send accepted request to server |
38 | 48 |
const acceptRequest = async (user) => { |
49 |
try { |
|
39 | 50 |
|
40 |
const acceptedRequests = { |
|
41 |
id: user.id, |
|
42 |
status: 'ACCEPTED', |
|
43 |
} |
|
51 |
const acceptedRequests = {
|
|
52 |
id: user.id,
|
|
53 |
status: 'ACCEPTED',
|
|
54 |
}
|
|
44 | 55 |
|
45 |
api_fetch.sendAcceptedRequest(acceptedRequests).then((data) => { |
|
46 |
|
|
47 |
const userProps = { |
|
48 |
title: user.title, |
|
49 |
id: 0, |
|
56 |
await api_fetch.sendAcceptedRequest(acceptedRequests).then(() => { |
|
57 |
|
|
58 |
const userProps = { |
|
59 |
title: user.title, |
|
60 |
id: 0, |
|
61 |
type: user.type, |
|
50 | 62 |
type: user.type, |
51 |
start: user.start |
|
52 |
} |
|
53 |
//concat new request to current ones |
|
63 |
type: user.type, |
|
64 |
start: user.start |
|
65 |
} |
|
66 |
//concat new request to current ones |
|
54 | 67 |
props.setRequest((acceptedRequest) => acceptedRequest.concat(userProps)) |
55 |
//request accept button |
|
68 |
//request accept button
|
|
56 | 69 |
props.setUser((pendingRequest) => pendingRequest.filter((item) => item !== user)); |
57 |
}).catch(response => { |
|
58 |
alert(response) |
|
59 |
}) |
|
70 |
}) |
|
71 |
} catch (e) { |
|
72 |
throw 'error catch GET DATA APP (getCurrentProfile)' |
|
73 |
} |
|
60 | 74 |
} |
61 | 75 |
|
62 |
|
|
63 | 76 |
|
64 | 77 |
//send rejected request to server |
65 | 78 |
const declineRequest = async (user) => { |
79 |
try{ |
|
66 | 80 |
|
67 |
const rejectedRequest = { |
|
68 |
id: user.id, |
|
69 |
status: 'REJECTED', |
|
70 |
} |
|
81 |
const rejectedRequest = {
|
|
82 |
id: user.id,
|
|
83 |
status: 'REJECTED',
|
|
84 |
}
|
|
71 | 85 |
|
72 |
api_fetch.sendRejectedRequest(rejectedRequest).then((data) => {
|
|
73 |
//request cancel button |
|
86 |
await api_fetch.sendRejectedRequest(rejectedRequest);
|
|
87 |
|
|
74 | 88 |
props.setUser((acceptedRequest) => acceptedRequest.filter((item) => item !== user)) |
75 |
}).catch(reason => { |
|
76 |
alert(reason) |
|
77 |
}); |
|
89 |
|
|
90 |
const usersOverview = await api_fetch.getUsersOverview(); |
|
91 |
props.setEmployees(usersOverview); |
|
92 |
|
|
93 |
} catch (e) { |
|
94 |
alert(e) |
|
95 |
} |
|
78 | 96 |
} |
79 | 97 |
|
80 | 98 |
return ( |
... | ... | |
84 | 102 |
<div className="offs-items column"> |
85 | 103 |
<div className="offs-item row"> |
86 | 104 |
<table> |
105 |
{/* {props.userRequest.length > 0 |
|
106 |
? */} |
|
87 | 107 |
<tbody> |
88 | 108 |
<tr> |
89 | 109 |
<th>Name</th> |
... | ... | |
102 | 122 |
</tr> |
103 | 123 |
))} |
104 | 124 |
</tbody> |
125 |
{/* : |
|
126 |
<tbody> |
|
127 |
<p>There are no requests.</p> |
|
128 |
</tbody> |
|
129 |
} */} |
|
130 |
|
|
105 | 131 |
</table> |
106 | 132 |
</div> |
107 | 133 |
</div> |
client/src/YourRequests.js | ||
---|---|---|
1 | 1 |
import React, { useEffect } from 'react'; |
2 | 2 |
import './App.css'; |
3 |
import moment from 'moment'; |
|
3 | 4 |
import * as api_fetch from './api' |
4 | 5 |
|
5 | 6 |
function YourRequests(props) { |
... | ... | |
21 | 22 |
{ |
22 | 23 |
title: props.userName.name, |
23 | 24 |
id: request.id, |
24 |
start: b,
|
|
25 |
status: request.status, |
|
26 |
type: request.type
|
|
25 |
start: moment(b).format("D.M.YYYY"),
|
|
26 |
status: request.status = request.status.toLowerCase(),
|
|
27 |
type: convertVacationType(request.type)
|
|
27 | 28 |
} |
28 | 29 |
) |
29 | 30 |
})) |
... | ... | |
31 | 32 |
alert(reason) |
32 | 33 |
}); |
33 | 34 |
} |
35 |
|
|
36 |
function convertVacationType(vacationType) { |
|
37 |
// vacationType = 'SICK_DAY' ? 'sickday' : 'holiday' |
|
38 |
|
|
39 |
// if (vacationType = 'SICK_DAY') { |
|
40 |
// return: 'sickday', |
|
41 |
// } else { |
|
42 |
// return: 'holiday' |
|
43 |
// } |
|
44 |
|
|
45 |
switch (vacationType) { |
|
46 |
case 'SICK_DAY' : |
|
47 |
return 'sickday'; |
|
48 |
case 'HOLIDAY': |
|
49 |
return 'holiday'; |
|
50 |
} |
|
51 |
} |
|
34 | 52 |
|
35 | 53 |
|
36 | 54 |
return ( |
... | ... | |
40 | 58 |
<div className="offs-items column"> |
41 | 59 |
<div className="offs-item row"> |
42 | 60 |
<table> |
61 |
{props.userRequest.length > 0 ? |
|
62 |
|
|
43 | 63 |
<tbody> |
44 | 64 |
<tr> |
45 | 65 |
<th>Name</th> |
... | ... | |
48 | 68 |
<th>Status</th> |
49 | 69 |
</tr> |
50 | 70 |
{props.userRequest.map(user => ( |
51 |
<tr key={user.id}> |
|
71 |
<tr key={user.id}>
|
|
52 | 72 |
<td>{user.title}</td> |
53 | 73 |
<td>{user.type}</td> |
54 | 74 |
<td>{user.end ? user.start + " - " + user.end : user.start}</td> |
... | ... | |
56 | 76 |
</tr> |
57 | 77 |
))} |
58 | 78 |
</tbody> |
79 |
: |
|
80 |
<tbody> |
|
81 |
<div>No requests</div> |
|
82 |
</tbody>} |
|
59 | 83 |
</table> |
60 | 84 |
</div> |
61 | 85 |
</div> |
client/src/api.js | ||
---|---|---|
1 |
|
|
1 | 2 |
const http = 'http://devcz.yoso.fi:8090/ymanager'; |
2 | 3 |
|
3 | 4 |
// ******************** GET DATA APP getCurrentProfile ******************** |
4 | 5 |
|
5 | 6 |
export const getCurrentProfile = async () => { |
6 | 7 |
|
7 |
try { |
|
8 |
const response = await fetch( |
|
8 |
let response; |
|
9 |
|
|
10 |
try { |
|
11 |
response = await fetch( |
|
9 | 12 |
`${http}/users/current/profile`, { |
10 | 13 |
headers: { |
11 | 14 |
Authorization: 1 |
12 | 15 |
} |
13 | 16 |
} |
14 |
); |
|
17 |
); |
|
18 |
} catch (e) { |
|
19 |
throw 'Server is not available' |
|
20 |
} |
|
15 | 21 |
|
16 |
if (response.ok) { |
|
17 |
const data = await response.json(); |
|
18 |
return { |
|
19 |
name: data.firstName + ' ' + data.lastName, |
|
20 |
role: data.role, |
|
21 |
id: data.id, |
|
22 |
holiday: data.vacationCount, |
|
23 |
sickday: data.sickDayCount |
|
22 |
if (response.ok) { |
|
23 |
const data = await response.json(); |
|
24 |
|
|
25 |
return { |
|
26 |
name: data.firstName + ' ' + data.lastName, |
|
27 |
role: data.role, |
|
28 |
id: data.id, |
|
29 |
holiday: data.vacationCount, |
|
30 |
sickday: data.sickDayCount, |
|
31 |
takenSickday: data.takenSickDayCount |
|
24 | 32 |
} |
25 |
} else { |
|
26 |
if(response.status === 400) { |
|
27 |
throw 'error 400 GET DATA APP (getCurrentProfile)' |
|
28 |
} |
|
29 |
else if (response.status === 500) { |
|
30 |
throw 'error 500 GET DATA APP (getCurrentProfile)' |
|
31 |
} |
|
32 |
else { |
|
33 |
throw 'error GET DATA APP (getCurrentProfile)' |
|
34 |
} |
|
33 |
} else { |
|
34 |
switch (response.status) { |
|
35 |
case 401: |
|
36 |
throw new Error('Not authenticated.') |
|
37 |
case 500: |
|
38 |
throw new Error('Internal server error.') |
|
39 |
default: |
|
40 |
throw new Error(response.statusText) |
|
41 |
} |
|
35 | 42 |
} |
36 |
|
|
37 |
} catch (e) { |
|
38 |
throw 'error catch GET DATA APP (getCurrentProfile)' |
|
39 |
} |
|
40 | 43 |
} |
41 | 44 |
|
42 | 45 |
// ******************** LOAD DATA to CALENDAR - EMPLOYEE ******************** |
43 | 46 |
export const getUserCalendar = async (userName, fromDate ) => { |
47 |
|
|
48 |
let response; |
|
49 |
|
|
44 | 50 |
try { |
45 |
const response = await fetch( |
|
46 |
`${http}/user/${userName.id}/calendar?from=${fromDate}&status=ACCEPTED&status=REJECTED`, { |
|
47 |
headers: { |
|
48 |
'Accept': 'application/json', |
|
49 |
Authorization: 6 |
|
50 |
}, |
|
51 |
method: 'GET', |
|
52 |
} |
|
53 |
); |
|
51 |
response = await fetch( |
|
52 |
`${http}/user/${userName.id}/calendar?from=${fromDate}&status=ACCEPTED&status=REJECTED`, { |
|
53 |
headers: { |
|
54 |
'Accept': 'application/json', |
|
55 |
Authorization: 6 |
|
56 |
}, |
|
57 |
method: 'GET', |
|
58 |
} |
|
59 |
); |
|
60 |
} catch (e) { |
|
61 |
throw 'Server is not available' |
|
62 |
} |
|
54 | 63 |
|
55 | 64 |
if (response.ok) { |
56 |
const data = await response.json(); |
|
65 |
const data = await response.json();
|
|
57 | 66 |
|
58 |
return data.filter(day => { |
|
59 |
return day.status !== 'PENDING' |
|
60 |
}).map(day => { |
|
67 |
return data.filter(day => {
|
|
68 |
return day.status !== 'PENDING'
|
|
69 |
}).map(day => {
|
|
61 | 70 |
|
62 | 71 |
const newDate = day.date.split("/").join("-"); |
63 | 72 |
|
64 | 73 |
return ({ |
65 |
title: userName.name, |
|
66 |
start: newDate, |
|
67 |
backgroundColor: day.status === 'REJECTED' ? 'red' : 'green' |
|
74 |
title: userName.name,
|
|
75 |
start: newDate,
|
|
76 |
backgroundColor: day.status === 'REJECTED' ? 'red' : 'green'
|
|
68 | 77 |
}) |
69 | 78 |
}) |
70 |
} else { |
|
71 |
if(response.status === 400) { |
|
72 |
throw 'error 400 LOADING DATA (CALENDAR, EMPLOYEE)' |
|
73 |
} |
|
74 |
else if (response.status === 500) { |
|
75 |
throw 'error 500 LOADING DATA (CALENDAR, EMPLOYEE)' |
|
76 |
} |
|
77 |
else { |
|
78 |
throw 'error LOADING DATA (CALENDAR, EMPLOYEE)' |
|
79 |
} else { |
|
80 |
switch (response.status) { |
|
81 |
case 400: |
|
82 |
throw new Error('Bad request. Check query parameters.') |
|
83 |
case 401: |
|
84 |
throw new Error('Not authenticated.') |
|
85 |
case 403: |
|
86 |
throw new Error('Not authorized.') |
|
87 |
case 404: |
|
88 |
throw new Error('User with given ID does not exist.') |
|
89 |
case 500: |
|
90 |
throw new Error('Internal server error.') |
|
91 |
default: |
|
92 |
throw new Error(response.statusText) |
|
93 |
} |
|
79 | 94 |
} |
80 | 95 |
} |
81 |
} catch (e) { |
|
82 |
throw 'error catch LOADING DATA (CALENDAR, EMPLOYEE)' |
|
83 |
} |
|
84 |
} |
|
85 | 96 |
|
86 | 97 |
// ******************** LOAD DATA to CALENDAR - EMPLOYER ******************** |
98 |
|
|
87 | 99 |
export const getAdminCalendar = async () => { |
88 |
try { |
|
89 |
const response = await fetch( |
|
90 |
'http://devcz.yoso.fi:8090/ymanager/users/requests/vacation?status=ACCEPTED', { |
|
100 |
|
|
101 |
let response; |
|
102 |
|
|
103 |
try { |
|
104 |
response = await fetch( |
|
105 |
`${http}/users/requests/vacation?status=ACCEPTED`, { |
|
91 | 106 |
headers: { |
92 | 107 |
'Accept': 'application/json', |
93 | 108 |
Authorization: 1 |
... | ... | |
95 | 110 |
method: 'GET', |
96 | 111 |
} |
97 | 112 |
); |
113 |
} catch (e) { |
|
114 |
throw 'Server is not available' |
|
115 |
} |
|
98 | 116 |
|
99 |
if (response.ok) {
|
|
117 |
if (response.ok) { |
|
100 | 118 |
const data = await response.json(); |
101 | 119 |
|
102 | 120 |
return data.map(day => { |
... | ... | |
109 | 127 |
}) |
110 | 128 |
}) |
111 | 129 |
} else { |
112 |
if(response.status === 400) { |
|
113 |
throw 'error 400 LOADING DATA (CALENDAR, EMPLOYER)' |
|
114 |
} |
|
115 |
else if (response.status === 500) { |
|
116 |
throw 'error 500 LOADING DATA (CALENDAR, EMPLOYER))' |
|
117 |
} |
|
118 |
else { |
|
119 |
throw 'error LOADING DATA (CALENDAR, EMPLOYER)' |
|
130 |
switch (response.status) { |
|
131 |
case 400: |
|
132 |
throw new Error('Bad request. Check query parameters.') |
|
133 |
case 401: |
|
134 |
throw new Error('Not authenticated.') |
|
135 |
case 403: |
|
136 |
throw new Error('Not authorized.') |
|
137 |
case 500: |
|
138 |
throw new Error('Internal server error.') |
|
139 |
default: |
|
140 |
throw new Error(response.statusText) |
|
120 | 141 |
} |
121 | 142 |
} |
122 |
} catch (e) { |
|
123 |
throw 'error catch LOADING DATA (CALENDAR, EMPLOYER)' |
|
124 |
} |
|
125 | 143 |
} |
126 | 144 |
|
127 | 145 |
// ******************** ADD EVENT to CALENDAR - EMPLOYEE ******************** |
146 |
|
|
128 | 147 |
export async function addEventApi(dataAddEventEmployee) { |
129 |
try { |
|
148 |
let response; |
|
149 |
|
|
150 |
try { |
|
130 | 151 |
// send accepted request to server |
131 |
const response = await fetch('http://devcz.yoso.fi:8090/ymanager/user/calendar/create', {
|
|
152 |
response = await fetch(`${http}/user/calendar/create`, {
|
|
132 | 153 |
headers: { |
133 | 154 |
Authorization: 6, |
134 | 155 |
'Content-Type': 'application/json', |
... | ... | |
137 | 158 |
// object which is sent to server |
138 | 159 |
body: JSON.stringify(dataAddEventEmployee), |
139 | 160 |
}); |
140 |
if (response.ok) { |
|
161 |
} catch (e) { |
|
162 |
throw 'Server is not available' |
|
163 |
} |
|
164 |
|
|
165 |
if (response.ok) { |
|
141 | 166 |
|
142 |
const response = await fetch(
|
|
143 |
'http://devcz.yoso.fi:8090/ymanager/users/requests/vacation?status=PENDING', {
|
|
144 |
headers: {
|
|
145 |
Authorization: 1
|
|
146 |
},
|
|
147 |
});
|
|
148 |
const data = await response.json();
|
|
167 |
response = await fetch( |
|
168 |
`${http}/users/requests/vacation?status=PENDING`, {
|
|
169 |
headers: { |
|
170 |
Authorization: 1 |
|
171 |
}, |
|
172 |
}); |
|
173 |
const data = await response.json(); |
|
149 | 174 |
|
150 | 175 |
return data.map(request => { |
151 | 176 |
const a = request.date; |
... | ... | |
163 | 188 |
}) |
164 | 189 |
|
165 | 190 |
} else { |
166 |
|
|
167 |
if(response.status === 400) { |
|
168 |
throw 'error 400 ADD EVENT - EMPLOYEE' |
|
169 |
} |
|
170 |
else if (response.status === 500) { |
|
171 |
throw 'error 500 ADD EVENT - EMPLOYEE' |
|
191 |
switch (response.status) { |
|
192 |
case 400: |
|
193 |
throw new Error('Bad request. Check request body.') |
|
194 |
case 401: |
|
195 |
throw new Error('Not authenticated.') |
|
196 |
case 403: |
|
197 |
throw new Error('Not authorized.') |
|
198 |
case 500: |
|
199 |
throw new Error('Internal server error.') |
|
200 |
default: |
|
201 |
throw new Error(response.statusText) |
|
202 |
} |
|
172 | 203 |
} |
173 |
else { |
|
174 |
throw 'error ADD EVENT - EMPLOYEE' |
|
175 |
} |
|
176 |
} |
|
177 |
} catch (e) { |
|
178 |
throw 'error catch ADD EVENT - EMPLOYEE' |
|
179 |
} |
|
180 | 204 |
} |
181 | 205 |
|
182 | 206 |
// ******************** ADD EVENT to CALENDAR - EMPLOYER ******************** |
207 |
|
|
183 | 208 |
export async function addEventApiAdmin(dataAddEventAdmin) { |
209 |
let response; |
|
210 |
|
|
184 | 211 |
try { |
185 |
// send accepted request to server
|
|
186 |
const response = await fetch('http://devcz.yoso.fi:8090/ymanager/user/calendar/create', {
|
|
187 |
headers: {
|
|
188 |
Authorization: 1,
|
|
189 |
'Content-Type': 'application/json',
|
|
190 |
},
|
|
191 |
method: 'POST',
|
|
212 |
// send accepted request to server |
|
213 |
response = await fetch(`${http}/user/calendar/create`, {
|
|
214 |
headers: { |
|
215 |
Authorization: 1, |
|
216 |
'Content-Type': 'application/json', |
|
217 |
}, |
|
218 |
method: 'POST', |
|
192 | 219 |
// object which is sent to server |
193 |
body: JSON.stringify(dataAddEventAdmin), |
|
194 |
}); |
|
195 |
if (response.ok) { |
|
196 |
return; |
|
197 |
} else { |
|
198 |
if(response.status === 400) { |
|
199 |
throw('error 400 ADD EVENT ADMIN - EMPLOYER') |
|
200 |
} |
|
201 |
else if (response.status === 500) { |
|
202 |
throw ('error 500 ADD EVENT ADMIN - EMPLOYER') |
|
203 |
} |
|
204 |
else { |
|
205 |
throw('error ADD EVENT ADMIN - EMPLOYER') |
|
206 |
} |
|
207 |
} |
|
220 |
body: JSON.stringify(dataAddEventAdmin), |
|
221 |
}); |
|
208 | 222 |
} catch (e) { |
209 |
throw('error catch ADD EVENT ADMIN - EMPLOYER') |
|
210 |
} |
|
223 |
throw 'Server is not available' |
|
224 |
} |
|
225 |
|
|
226 |
if (!response.ok) { |
|
227 |
switch (response.status) { |
|
228 |
case 400: |
|
229 |
throw new Error('Bad request. Check request body.') |
|
230 |
case 401: |
|
231 |
throw new Error('Not authenticated.') |
|
232 |
case 403: |
|
233 |
throw new Error('Not authorized.') |
|
234 |
case 500: |
|
235 |
throw new Error('Internal server error.') |
|
236 |
default: |
|
237 |
throw new Error(response.statusText) |
|
238 |
} |
|
239 |
} |
|
211 | 240 |
} |
212 | 241 |
|
213 | 242 |
// ******************** GET DATA to OVERVIEW - EMPLOYER ******************** |
243 |
|
|
214 | 244 |
export const getUsersOverview = async () => { |
245 |
let response; |
|
246 |
|
|
215 | 247 |
try { |
216 |
const response = await fetch (
|
|
217 |
'http://devcz.yoso.fi:8090/ymanager/users', {
|
|
248 |
response = await fetch ( |
|
249 |
`${http}/users`, {
|
|
218 | 250 |
headers: { |
219 | 251 |
Authorization: 1 } |
220 | 252 |
} |
221 | 253 |
); |
254 |
} catch (e) { |
|
255 |
throw 'Server is not available' |
|
256 |
} |
|
222 | 257 |
|
223 |
if (response.ok) { |
|
258 |
if (response.ok) {
|
|
224 | 259 |
|
225 |
const data = await response.json(); |
|
226 |
return data.map(user => { |
|
260 |
const data = await response.json();
|
|
261 |
return data.map(user => {
|
|
227 | 262 |
|
228 |
return ( |
|
229 |
{ |
|
263 |
return ({ |
|
230 | 264 |
name: user.firstName + ' ' + user.lastName, |
231 | 265 |
id: user.id, |
232 | 266 |
sickday: user.sickDayCount, |
233 | 267 |
holiday: user.vacationCount, |
268 |
takenSickday: user.takenSickDayCount, |
|
234 | 269 |
role: user.role |
235 | 270 |
}) |
236 |
}) |
|
237 |
} else {
|
|
238 |
if(response.status === 400) {
|
|
239 |
throw 'error 400 GET DATA (OVERVIEW, EMPLOYER)'
|
|
240 |
}
|
|
241 |
else if (response.status === 500) {
|
|
242 |
throw 'error 500 GET DATA (OVERVIEW, EMPLOYER)'
|
|
243 |
}
|
|
244 |
else {
|
|
245 |
throw 'error GET DATA (OVERVIEW, EMPLOYER)'
|
|
246 |
}
|
|
247 |
}
|
|
248 |
} catch (e) {
|
|
249 |
throw 'error catch GET DATA (OVERVIEW, EMPLOYER)'
|
|
271 |
})
|
|
272 |
} else {
|
|
273 |
switch (response.status) {
|
|
274 |
case 400:
|
|
275 |
throw new Error('Bad request. Check query parameters.')
|
|
276 |
case 401:
|
|
277 |
throw new Error('Not authenticated.')
|
|
278 |
case 403:
|
|
279 |
throw new Error('Not authorized.')
|
|
280 |
case 500:
|
|
281 |
throw new Error('Internal server error.')
|
|
282 |
default:
|
|
283 |
throw new Error(response.statusText)
|
|
284 |
}
|
|
250 | 285 |
} |
251 | 286 |
} |
252 | 287 |
|
253 | 288 |
// ******************** SAVE DATA to OVERVIEW - EMPLOYER ******************** |
289 |
|
|
254 | 290 |
export async function saveDataOverview(dataOverviewObject) { |
291 |
let response; |
|
292 |
|
|
255 | 293 |
try { |
256 | 294 |
// send accepted request to server |
257 |
const response = await fetch('http://devcz.yoso.fi:8090/ymanager/user/settings', {
|
|
295 |
response = await fetch(`${http}/user/settings`, {
|
|
258 | 296 |
headers: { |
259 | 297 |
Authorization: 1, |
260 | 298 |
'Content-Type': 'application/json', |
... | ... | |
264 | 302 |
// object which is sent to server |
265 | 303 |
body: JSON.stringify(dataOverviewObject), |
266 | 304 |
}); |
267 |
console.log(response.status) |
|
268 |
if (response.status === 400) { |
|
269 |
throw 'error 400 SAVE DATA (OVERVIEW, EMPLOYER)' |
|
270 |
} |
|
271 |
else if (response.status === 500) { |
|
272 |
throw 'error 500 SAVE DATA (OVERVIEW, EMPLOYER)' |
|
273 |
} |
|
274 |
else if (!response.ok) { |
|
275 |
throw 'error SAVE DATA (OVERVIEW, EMPLOYER)' |
|
276 |
} |
|
277 |
|
|
278 | 305 |
} catch (e) { |
279 |
throw 'error catch SAVE DATA (OVERVIEW, EMPLOYER'
|
|
306 |
throw 'Server is not available'
|
|
280 | 307 |
} |
308 |
|
|
309 |
if (!response.ok) { |
|
310 |
switch (response.status) { |
|
311 |
case 400: |
|
312 |
throw new Error('Bad request. Check query parameters.') |
|
313 |
case 401: |
|
314 |
throw new Error('Not authenticated.') |
|
315 |
case 403: |
|
316 |
throw new Error('Not authorized.') |
|
317 |
case 500: |
|
318 |
throw new Error('Internal server error.') |
|
319 |
default: |
|
320 |
throw new Error(response.statusText) |
|
321 |
} |
|
322 |
} |
|
281 | 323 |
} |
282 | 324 |
|
283 | 325 |
// ******************** LOAD DATA to SETTING - EMPLOYER ******************** |
284 | 326 |
export const getSettingData = async () => { |
327 |
let response; |
|
328 |
|
|
285 | 329 |
try { |
286 | 330 |
const response = await fetch( |
287 |
'http://devcz.yoso.fi:8090/ymanager/settings', {
|
|
331 |
`${http}/settings`, {
|
|
288 | 332 |
headers: { |
289 | 333 |
Authorization: 1 |
290 | 334 |
} |
291 | 335 |
}); |
292 |
|
|
293 |
if (response.ok) { |
|
294 |
const data = await response.json(); |
|
295 |
return { |
|
296 |
sickday: data.sickDayCount, |
|
297 |
} |
|
298 |
} else { |
|
299 |
if(response.status === 400) { |
|
300 |
throw 'error 400 LOADING DATA (SETTING, EMPLOYER)' |
|
301 |
} |
|
302 |
else if (response.status === 500) { |
|
303 |
throw 'error 500 LOADING DATA (SETTING, EMPLOYER)' |
|
304 |
} |
|
305 |
else { |
|
306 |
throw 'error LOADING DATA (SETTING, EMPLOYER)' |
|
307 |
} |
|
308 |
} |
|
309 | 336 |
} catch (e) { |
310 |
throw 'error catch LOADING DATA (SETTING, EMPLOYER)' |
|
337 |
throw 'Server is not available' |
|
338 |
} |
|
339 |
|
|
340 |
if (response.ok) { |
|
341 |
const data = await response.json(); |
|
342 |
return { |
|
343 |
sickday: data.sickDayCount, |
|
344 |
} |
|
345 |
} else { |
|
346 |
switch (response.status) { |
|
347 |
case 500: |
|
348 |
throw new Error('Internal server error.') |
|
349 |
default: |
|
350 |
throw new Error(response.statusText) |
|
351 |
} |
|
311 | 352 |
} |
353 |
|
|
312 | 354 |
} |
313 | 355 |
|
314 | 356 |
// ******************** SAVE DATA to SETTING - EMPLOYER ******************** |
315 | 357 |
export async function saveDataSetting(dataSettingObject) { |
358 |
let response; |
|
359 |
|
|
316 | 360 |
try { |
317 |
const response = await fetch('http://devcz.yoso.fi:8090/ymanager/settings', {
|
|
361 |
response = await fetch(`${http}/settings`, {
|
|
318 | 362 |
headers: { |
319 |
'Authorization': 6,
|
|
363 |
'Authorization': 1,
|
|
320 | 364 |
'Content-Type': 'application/json' |
321 | 365 |
}, |
322 | 366 |
method: 'POST', |
323 | 367 |
body: JSON.stringify(dataSettingObject), |
324 | 368 |
}); |
369 |
} catch (e) { |
|
370 |
throw 'Server is not available' |
|
371 |
} |
|
325 | 372 |
|
373 |
if (!response.ok) { |
|
326 | 374 |
switch (response.status) { |
327 |
case 200: |
|
328 |
throw '...' |
|
375 |
case 401: |
|
376 |
throw new Error('Not authenticated.') |
|
377 |
case 403: |
|
378 |
throw new Error('Not authorized.') |
|
329 | 379 |
case 500: |
330 |
throw ''
|
|
380 |
throw new Error('Internal server error.')
|
|
331 | 381 |
default: |
332 |
throw response.statusText |
|
333 |
|
|
334 |
} |
|
335 |
|
|
336 |
if(response.status === 400) { |
|
337 |
throw 'error 400 SAVE DATA (OVERVIEW, EMPLOYER)' |
|
338 |
} |
|
339 |
else if (response.status === 500) { |
|
340 |
throw 'error 500 SAVE DATA (OVERVIEW, EMPLOYER)' |
|
341 |
} |
|
342 |
else if (!response.ok) { |
|
343 |
throw 'error SAVE DATA (OVERVIEW, EMPLOYER)' |
|
344 |
} |
|
345 |
} catch (e) { |
|
346 |
throw 'error catch SAVE DATA (OVERVIEW, EMPLOYER)' |
|
347 |
} |
|
382 |
throw new Error(response.statusText) |
|
383 |
} |
|
384 |
} |
|
348 | 385 |
} |
349 | 386 |
|
350 | 387 |
// ****************** LOAD DATA to YOUR REQUESTS - EMPLOYEE ****************** |
351 | 388 |
|
352 | 389 |
export async function loadYourRequests() { |
390 |
let response; |
|
391 |
|
|
353 | 392 |
try { |
354 |
const response = await fetch(
|
|
355 |
'http://devcz.yoso.fi:8090/ymanager/user/6/calendar?from=2020/06/24&status=PENDING', {
|
|
393 |
response = await fetch( |
|
394 |
`${http}/user/6/calendar?from=2020/06/24&status=PENDING`, {
|
|
356 | 395 |
headers: { |
357 | 396 |
Authorization: 6 |
358 | 397 |
}, |
359 | 398 |
} |
360 | 399 |
); |
400 |
} catch (e) { |
|
401 |
throw 'Server is not available' |
|
402 |
} |
|
361 | 403 |
|
362 | 404 |
if (response.ok) { |
363 | 405 |
const data = await response.json(); |
364 | 406 |
return data; |
365 | 407 |
} else { |
366 |
if(response.status === 400) { |
|
367 |
alert('error 400 GET DATA (YOUR REQUEST)') |
|
368 |
} |
|
369 |
else if (response.status === 500) { |
|
370 |
alert ('error 500 GET DATA (YOUR REQUEST)') |
|
371 |
} |
|
372 |
else { |
|
373 |
alert('error GET DATA (YOUR REQUEST)') |
|
374 |
} |
|
375 |
} |
|
376 |
} catch (e) { |
|
377 |
console.log(e) |
|
378 |
alert('error catch GET DATA (YOUR REQUEST)') |
|
379 |
} |
|
408 |
switch (response.status) { |
|
409 |
case 400: |
|
410 |
throw new Error('Bad request. Check query parameters.') |
|
411 |
case 401: |
|
412 |
throw new Error('Not authenticated.') |
|
413 |
case 403: |
|
414 |
throw new Error('Not authorized.') |
|
415 |
case 500: |
|
416 |
throw new Error('Internal server error.') |
|
417 |
default: |
|
418 |
throw new Error(response.statusText) |
|
419 |
} |
|
420 |
} |
|
380 | 421 |
} |
381 | 422 |
|
382 |
// ****************** LOAD DATA - UPCOMING REQUESTS - EMPLOYER ****************** |
|
423 |
// ****************** LOAD DATA - UPCOMING REQUESTS - EMPLOYER ****************** //tady
|
|
383 | 424 |
export async function loadAdminRequests() { |
425 |
let response; |
|
426 |
|
|
384 | 427 |
try { |
385 |
const response = await fetch(
|
|
386 |
'http://devcz.yoso.fi:8090/ymanager/users/requests/vacation?status=PENDING', {
|
|
428 |
response = await fetch( |
|
429 |
`${http}/users/requests/vacation?status=PENDING`, {
|
|
387 | 430 |
headers: { |
388 | 431 |
Authorization: 1 |
389 | 432 |
} |
390 | 433 |
}, |
391 | 434 |
); |
392 |
|
|
393 |
if (response.ok) { |
|
435 |
} catch (e) { |
|
436 |
throw 'Server is not available' |
|
437 |
} |
|
438 |
|
|
439 |
if (response.ok) { |
|
394 | 440 |
const data = await response.json(); |
395 | 441 |
return data; |
396 | 442 |
} else { |
397 |
if(response.status === 400) { |
|
398 |
alert('error 400 GET DATA (UPCOMING REQUESTS)') |
|
399 |
} |
|
400 |
else if (response.status === 500) { |
|
401 |
alert ('error 500 GET DATA (UPCOMING REQUESTS)') |
|
402 |
} |
|
403 |
else { |
|
404 |
alert('error GET DATA (UPCOMING REQUESTS)') |
|
405 |
} |
|
443 |
switch (response.status) { |
|
444 |
case 400: |
|
445 |
throw new Error('Bad request. Check query parameters.') |
|
446 |
case 401: |
|
447 |
throw new Error('Not authenticated.') |
|
448 |
case 403: |
|
449 |
throw new Error('Not authorized.') |
|
450 |
case 500: |
|
451 |
throw new Error('Internal server error.') |
|
452 |
default: |
|
453 |
throw new Error(response.statusText) |
|
454 |
} |
|
406 | 455 |
} |
407 |
} catch (e) { |
|
408 |
alert('error catch GET DATA (UPCOMING REQUESTS)') |
|
409 |
} |
|
410 | 456 |
} |
411 | 457 |
|
412 | 458 |
// ************** SEND ACCEPTED DATA - UPCOMING REQUESTS - EMPLOYER ************** |
459 |
|
|
413 | 460 |
export async function sendAcceptedRequest(acceptedRequests) { |
461 |
let response; |
|
462 |
|
|
414 | 463 |
try { |
415 |
const response = await fetch('http://devcz.yoso.fi:8090/ymanager/user/requests?type=VACATION', {
|
|
464 |
response = await fetch(`${http}/user/requests?type=VACATION`, {
|
|
416 | 465 |
headers: { |
417 | 466 |
Authorization: 1, |
418 | 467 |
'Content-Type': 'application/json', |
... | ... | |
420 | 469 |
method: 'PUT', |
421 | 470 |
body: JSON.stringify(acceptedRequests), |
422 | 471 |
}); |
423 |
|
|
424 |
if (response.ok) { |
|
425 |
return; |
|
426 |
|
|
427 |
} else { |
|
428 |
if(response.status === 400) { |
|
429 |
alert('error 400 SEND ACCEPTED DATA (UPCOMING REQUESTS)') |
|
430 |
} |
|
431 |
else if (response.status === 500) { |
|
432 |
alert ('error 500 SEND ACCEPTED DATA (UPCOMING REQUESTS)') |
|
433 |
} |
|
434 |
else { |
|
435 |
alert('error SEND ACCEPTED DATA (UPCOMING REQUESTS)') |
|
436 |
} |
|
437 |
} |
|
438 | 472 |
} catch (e) { |
439 |
alert('error catch SEND ACCEPTED DATA (UPCOMING REQUESTS)')
|
|
473 |
throw 'Server is not available'
|
|
440 | 474 |
} |
475 |
|
|
476 |
if (!response.ok) { |
|
477 |
switch (response.status) { |
|
478 |
case 400: |
|
479 |
throw new Error('Bad request. Check query parameters and request body.') |
|
480 |
case 401: |
|
481 |
throw new Error('Not authenticated.') |
|
482 |
case 403: |
|
483 |
throw new Error('Not authorized.') |
|
484 |
case 404: |
|
485 |
throw new Error('Neither vacation nor authorization request with given ID exists.') |
|
486 |
case 500: |
|
487 |
throw new Error('Internal server error.') |
|
488 |
default: |
|
489 |
throw new Error(response.statusText) |
|
490 |
} |
|
491 |
} |
|
441 | 492 |
} |
442 | 493 |
|
443 | 494 |
// ************** SEND REJECTED DATA - UPCOMING REQUESTS - EMPLOYER ************** |
444 | 495 |
|
445 | 496 |
export async function sendRejectedRequest(rejectedRequest) { |
497 |
let response; |
|
498 |
|
|
446 | 499 |
try { |
447 |
const response = await fetch('http://devcz.yoso.fi:8090/ymanager/user/requests?type=VACATION', {
|
|
500 |
response = await fetch(`${http}/user/requests?type=VACATION`, {
|
|
448 | 501 |
headers: { |
449 | 502 |
Authorization: 1, |
450 | 503 |
'Content-Type': 'application/json', |
... | ... | |
452 | 505 |
method: 'PUT', |
453 | 506 |
body: JSON.stringify(rejectedRequest), |
454 | 507 |
}); |
455 |
|
|
456 |
if (response.ok) { |
|
457 |
return; |
|
458 |
|
|
459 |
} else { |
|
460 |
if(response.status === 400) { |
|
461 |
alert('error 400 SEND REJECTED DATA (UPCOMING REQUESTS)') |
|
462 |
} |
|
463 |
else if (response.status === 500) { |
|
464 |
alert ('error 500 SEND REJECTED DATA (UPCOMING REQUESTS)') |
|
465 |
} |
|
466 |
else { |
|
467 |
alert('error SEND REJECTED DATA (UPCOMING REQUESTS)') |
|
468 |
} |
|
469 |
} |
|
470 |
} catch (e) { |
|
471 |
alert('error catch SEND REJECTED DATA (UPCOMING REQUESTS)') |
|
508 |
} catch (e) { |
|
509 |
throw 'Server is not available' |
|
510 |
} |
|
511 |
|
|
512 |
if (!response.ok) { |
|
513 |
switch (response.status) { |
|
514 |
case 400: |
|
515 |
throw new Error('Bad request. Check query parameters and request body.') |
|
516 |
case 401: |
|
517 |
throw new Error('Not authenticated.') |
|
518 |
case 403: |
|
519 |
throw new Error('Not authorized.') |
|
520 |
case 404: |
|
521 |
throw new Error('Neither vacation nor authorization request with given ID exists.') |
|
522 |
case 500: |
|
523 |
throw new Error('Internal server error.') |
|
524 |
default: |
|
525 |
throw new Error(response.statusText) |
|
526 |
} |
|
472 | 527 |
} |
473 | 528 |
} |
474 |
|
|
475 |
|
Také k dispozici: Unified diff
re #58 client part(especially rebuilt api.js, all fetches, little edits in YourRequests/UpcomingRequests and fixed bugs in calendar and overview (add event, save, post, numbers)