commit 9f045397a5832c9a8d8bdfe21001c748c2e1f192
Author: plundrichov <monika.plundrichova@yoso.fi>
Date:   Fri Jul 3 10:18:48 2020 +0200

    re #58 Refactoring, every fetch moved to api.js

diff --git a/client/src/App.css b/client/src/App.css
index 2980b2e..d2866f5 100644
--- a/client/src/App.css
+++ b/client/src/App.css
@@ -13,6 +13,25 @@
     flex-direction: row;
 }
 
+/* --------------APP------------------*/
+
+.permissionText {
+    text-align: center;
+    justify-content: center;
+    left: 50%;
+    top: 50%;
+    transform: translate(-50%, -50%);
+    position: absolute;
+    font-size: 24px;
+    font-weight: bold;
+    color: rgb(255, 255, 255);
+    width: 400px;
+    height: 400px;
+    border-radius: 50%;
+    background-color: rgba(236, 236, 236, 0.192);
+    padding: 20px;
+}
+
 /* ------------- Navbar --------------- */
 
 .top-nav {
@@ -260,7 +279,7 @@ input {
 }
 .login-container h1 {
     color: white;
-    font-size: 110px;
+    font-size: 90px;
 }
 /* ------------- SETTING -------------------*/
 
diff --git a/client/src/App.js b/client/src/App.js
index 3a81207..dd99f97 100644
--- a/client/src/App.js
+++ b/client/src/App.js
@@ -9,8 +9,6 @@ import YourRequests from './YourRequests';
 import Setting from './Setting';
 import LogOut from './LogOut';
 import Login from './Login';
-// import Komponenta1 from './Komponenta1';
-// import Komponenta2 from './Komponenta2';
 import { BrowserRouter, Route, Switch } from "react-router-dom";
 import * as api_fetch from './api'
 
@@ -19,6 +17,8 @@ function App() {
   useEffect(() => {
     api_fetch.getCurrentProfile().then(currentProfile => {
     setUserName(currentProfile);
+    }).catch(reason => {
+      alert(reason)
     });
   }, []);
 
@@ -36,7 +36,12 @@ function App() {
         <div className="container">
         <Switch>
           <Route path="/" exact component={() => <Home userName={userName}/>}/>
-          <Route path="/setting"><Setting/></Route>
+          
+          <Route path="/setting">{userName.role === 'EMPLOYER' ? <Setting/>:
+           <div className="permissionText column">
+             <p>You don't have permission to access on this server.</p>
+            </div>}</Route> 
+
           <Route path="/logout"><LogOut/></Route>
           <Route path="/login"><Login/></Route>
         </Switch>  
@@ -59,10 +64,7 @@ const Home = (props) => {
   function getDataUserRequest() {
     return ([]);
   }
-
-  // const [data, setData] = useState([])
-  // const [todo, setTodo] = useState([])
-
+  
   return (
   <div className="container">
     <div className="main-content">
@@ -76,8 +78,3 @@ const Home = (props) => {
 
 export default App;
 
-  /* <Komponenta1 todo={todo} setTodo={setTodo}/>
-  <Komponenta2 todo={todo} setTodo={setTodo}/> */
-
-
- 
\ No newline at end of file
diff --git a/client/src/Calendar.js b/client/src/Calendar.js
index 1b3fcdb..484b8b0 100644
--- a/client/src/Calendar.js
+++ b/client/src/Calendar.js
@@ -16,21 +16,21 @@ function Calendar(props) {
     if (props.userName.id !== undefined) {
       props.userName.role === 'EMPLOYER'
         ?
-          api_fetch.getAdminCalendar().then(adminCalendar => {
-            props.setRequest(adminCalendar)
+          api_fetch.getAdminCalendar().then(adminCalendar => { 
+            props.setRequest(adminCalendar);
+          }).catch(reason => {
+            alert(reason)
           })
         :
           api_fetch.getUserCalendar(props.userName, todayTwo).then(userCalendar => {
-            props.setRequest(userCalendar)
+            props.setRequest(userCalendar);
+          }).catch(reason => {
+            alert(reason)
           });
     }
   }, [props.userName.id]);
 
-  // LOAD DATA from server to calendar **** EMPLOYEE ****
-  
-  // LOAD DATA from server to calendar **** EMPLOYER ****
-
-  //states
+//states
   const [isOpen, setOpen] = useState(false)
 
   const [whatDate, setDate] = useState('')
@@ -41,13 +41,36 @@ function Calendar(props) {
 
   var today = new Date();
 
-  // setting date to right format
+// setting date to right format
   today = today.toISOString().split('T')[0]
   const todayTwo = today.split("-").join("/")
 
+// LOAD DATA from server to calendar **** EMPLOYEE ****
+  
+// LOAD DATA from server to calendar **** EMPLOYER ****
+
 // ********************* ADD EVENT - EMPLOYEE **************************
 
+const addEvent = async (e) => {
+  e.preventDefault();
   
+  // setting an object
+  const newDate = whatDate.split("-").join("/");
+
+  const dataAddEventEmployee = {
+    type: typeRadio === 'sickday' ? 'SICK_DAY' : 'VACATION',
+    date: newDate,
+    from: typeRadio === 'sickday' ? null : "00:00",
+    to: typeRadio === 'sickday' ? null : moment().startOf('day').add(whatTime, "hours").format("hh:mm"),
+  }
+
+  api_fetch.addEventApi(dataAddEventEmployee).catch(reason => {
+    alert(reason)
+  });
+    
+    setOpen(false)
+  }
+ 
 // ********************* ADD EVENT ADMIN - EMPLOYER **************************
 
 const addEventAdmin = async (e) => {
@@ -56,53 +79,26 @@ const addEventAdmin = async (e) => {
 // setting an object
   const newDate = whatDate.split("-").join("/");
 
-  const peps = {
+  const dataAddEventAdmin = {
     type: typeRadio === 'sickday' ? 'SICK_DAY' : 'VACATION',
     date: newDate,
     from: typeRadio === 'sickday' ? null : "00:00",
     to: typeRadio === 'sickday' ? null : moment().startOf('day').add(whatTime, "hours").format("hh:mm"),
   };
 
-  api_fetch.tvojefunkce(peps)
-    
-  try {
-// send accepted request to server
-    const response = await fetch('http://devcz.yoso.fi:8090/ymanager/user/calendar/create', {
-      headers: {
-        Authorization: 1,
-        'Content-Type': 'application/json',
-      },
-      method: 'POST',
-// object which is sent to server
-      body: JSON.stringify(peps),
-    });
-    if (response.ok) {
-  
-
-  const userProps = {
-    title: props.userName.name,
-    start: whatDate
-  
-}
-//concat new request to current ones
-    props.setRequest((acceptedRequest) => acceptedRequest.concat(userProps))
-} else {
-  if(response.status === 400) {
-    alert('error 400 ADD EVENT ADMIN - EMPLOYER')
- }
-    else if (response.status === 500) {
-       alert ('error 500 ADD EVENT ADMIN - EMPLOYER')
-    }
-    else {
-       alert('error ADD EVENT ADMIN - EMPLOYER')
-    }
-}
-  } catch (e) {
-    alert('error catch ADD EVENT ADMIN - EMPLOYER')
+  api_fetch.addEventApiAdmin(dataAddEventAdmin).then(() => {
+    const userProps = {
+      title: props.userName.name, 
+      start: whatDate      
   }
+  //concat new request to current ones
+      props.setRequest((acceptedRequest) => acceptedRequest.concat(userProps))
+  }).catch(reason => {
+    alert(reason)
+  });
 
-
-  setOpen(false)}
+  setOpen(false)
+}
     
 
   return (
@@ -131,8 +127,8 @@ const addEventAdmin = async (e) => {
     <div className="calendar-form">
       {/* <form onSubmit={(e) => addEvent(e)}> */}
       <form onSubmit={props.userName.role === 'EMPLOYER' 
-      ? (e) => addEventAdmin(e).then(eventAdmin => { props.setUser(eventAdmin)}) 
-      : (e) => api_fetch.addEvent(e).then(userEvent => { props.setUser(userEvent)})
+      ? (e) => addEventAdmin(e)
+      : (e) => addEvent(e)
       }>
         <h2>Choose an option</h2>
         <div className="calendar-radio">
diff --git a/client/src/OverviewAdmin.js b/client/src/OverviewAdmin.js
index b9fce54..75173c4 100644
--- a/client/src/OverviewAdmin.js
+++ b/client/src/OverviewAdmin.js
@@ -1,53 +1,19 @@
 import React, { useState, useEffect } from 'react';
 import './App.css';
+import * as api_fetch from './api'
 
 
 const OverviewAdmin = () => {
 
-   useEffect( () => {
-      getData();
+   useEffect(() => {
+      api_fetch.getUsersOverview().then(usersOverview => {
+         setEmployees(usersOverview);
+         }).catch(reason => {
+         alert(reason)
+      });
    }, []);
 
-   const getData = async () => {
-      try {
-      const response = await fetch (
-         'http://devcz.yoso.fi:8090/ymanager/users', {
-          headers: {
-            Authorization: 1          }
-        }
-      );
-      
-   if (response.ok) {
-
-      const data = await response.json();
-      setEmployees(data.map(user => {
-
-         return (
-            {
-               name: user.firstName + ' ' + user.lastName,
-               id: user.id,
-               sickday: user.sickDayCount,
-               holiday: user.vacationCount,
-               role: user.role
-            })
-      }))
-   }  else {
-         if(response.status === 400) {
-            alert('error 400 GET DATA (OVERVIEW, EMPLOYER)')
-         }
-            else if (response.status === 500) {
-               alert ('error 500 GET DATA (OVERVIEW, EMPLOYER)')
-            }
-            else {
-               alert('error GET DATA (OVERVIEW, EMPLOYER)')
-            }
-   }
-} catch (e) {
-   console.log(e)
-   alert('spatne')
-   }
-}
-   
+   // states
    const [employees, setEmployees] = useState([
       {
          name: 'Sadam',
@@ -59,9 +25,10 @@ const OverviewAdmin = () => {
 
    const [isEdit, setEdit] = useState(false);
    const [editedUserId, setEditedUserId] = useState();
-   
    const [prevEdit, setPrevEdit] = useState();
+   
 
+   // functions
    function changeSickdays(newValue) {
       const newEmployees = employees.map(employee => {
          if (editedUserId === employee.id) {
@@ -91,48 +58,25 @@ const OverviewAdmin = () => {
    }
 
    const submitEdit = async (e) => {
-      try {
+      
       setEdit(isEdit === true ? false : true);
       setPrevEdit(employees);
       e.preventDefault();
 
       const found = employees.find(employee => editedUserId === employee.id);
       const foundPrevEdit = prevEdit.find(employee => editedUserId === employee.id);
-      console.log(found)
-
-
-   // send accepted request to server
-       const response = await fetch('http://devcz.yoso.fi:8090/ymanager/user/settings', {
-         headers: {
-           Authorization: 1,
-           'Content-Type': 'application/json',
-         },
-         method: 'PUT',
-
-   // object which is sent to server
-         body: JSON.stringify({
-           id: found.id,
-           vacationCount: Number(found.holiday) - foundPrevEdit.holiday,
-           sickDayCount: Number(found.sickday),
-           role: found.role
-         }),        
-       });
-       console.log(response.status)
-      if (response.status === 400) {
-         alert('error 400 SAVE DATA (OVERVIEW, EMPLOYER)')
-      }
-         else if (response.status === 500) {
-            alert('error 500 SAVE DATA (OVERVIEW, EMPLOYER)')
-         }
-            else if (!response.ok) {
-               alert('error SAVE DATA (OVERVIEW, EMPLOYER)')
-            }
-                   
-      } catch (e) {
-         alert('error catch SAVE DATA (OVERVIEW, EMPLOYER')
+
+      const dataOverviewObject = {
+         id: found.id,
+         vacationCount: Number(found.holiday) - foundPrevEdit.holiday,
+         sickDayCount: Number(found.sickday),
+         role: found.role
       }
-   }
 
+      api_fetch.saveDataOverview(dataOverviewObject).catch(reason => {
+         alert(reason)
+       });
+   }
 
    const cancel = () => {
       setEmployees(prevEdit)
@@ -148,8 +92,6 @@ const OverviewAdmin = () => {
       
      e.preventDefault();
    }
-
-   console.log(isEdit, editedUserId)
    
       return (
    <div>
diff --git a/client/src/Setting.js b/client/src/Setting.js
index 4b35f73..45e9fa0 100644
--- a/client/src/Setting.js
+++ b/client/src/Setting.js
@@ -1,6 +1,7 @@
 import React, { useState, useEffect } from 'react';
 import './App.css';
 import { Link } from 'react-router-dom';
+import * as api_fetch from './api'
 
 
 function Setting() {
@@ -8,98 +9,45 @@ function Setting() {
   const [sickdays, setSickdays] = useState([]);
 
   useEffect( () => {
-    getData();
+    api_fetch.getSettingData().then(settingData => {
+      setSetting(settingData);
+    }).catch(reason => {
+      alert(reason)
+    })
   }, []);
 
-  const getData = async () =>  {
-    try {
-      const response = await fetch(
-        'http://devcz.yoso.fi:8090/ymanager/settings', {
-          headers: {
-            Authorization: 1
-          }
-        }
-        );
-
-        if (response.ok) {
-        const data = await response.json();
-        setSetting({
-          sickday: data.sickDayCount,
-        })
-      } else {
-        if(response.status === 400) {
-          alert('error 400')
-       }
-          else if (response.status === 500) {
-             alert ('error 500')
-          }
-          else {
-             alert('spatne neco jinyho')
-          }
-      }
-    } catch (e) {
-      console.log(e)
-      alert('spatne vsechno')
-      }
-  }
-
   const submitSetting = async (e) => {
     e.preventDefault();
-    try {
-    const response = await fetch('http://devcz.yoso.fi:8090/ymanager/settings', {
-      headers: {
-        'Authorization': 1,
-        'Content-Type': 'application/json'
-      },
-      method: 'POST',
-      body: JSON.stringify({
-        "sickDayCount": Number(setting.sickday),
-        "notification": "2019/12/01 12:00:00"
-      }),
-    });
-
-
-    if (response.ok) {
-  } else {
-    if(response.status === 400) {
-      alert('error 400')
-   }
-      else if (response.status === 500) {
-         alert ('error 500')
-      }
-      else {
-         alert('spatne neco jinyho')
-      }
-  }
-} catch (e) {
-  console.log(e)
-  alert('spatne vsechno')
-  }
+    
+    const dataSettingObject = {
+      "sickDayCount": Number(setting.sickday),
+      "notification": "2019/12/01 12:00:00"  
+    }
 
+    api_fetch.saveDataSetting(dataSettingObject).catch(reason => {
+      alert(reason)
+    })
   }
-
-
-
+  // states
   const [setting, setSetting] = useState(
     {sickday: 5,
     holiday: 0
     }
   ) 
 
+  //functions
   function changeSickday(newValue) {
     setSetting(
        {sickday: newValue,
         holiday: setting.holiday
-      }
-    )
+    })
   }
 
   function changeHoliday(newValue) {
     setSetting(
       {sickday: setting.sickday,
        holiday: newValue
-      }
-    )
+    })
   }
 
   return (
diff --git a/client/src/UpcomingRequests.js b/client/src/UpcomingRequests.js
index 7017503..5402b20 100644
--- a/client/src/UpcomingRequests.js
+++ b/client/src/UpcomingRequests.js
@@ -1,6 +1,6 @@
 import React, { useEffect } from 'react';
 import './App.css';
-
+import * as api_fetch from './api'
 
 function UpcomingRequests(props) {
 
@@ -10,126 +10,71 @@ function UpcomingRequests(props) {
 
   // get requests from server
   const getData = async () => {
-    try {
-    const response = await fetch(
-      'http://devcz.yoso.fi:8090/ymanager/users/requests/vacation?status=PENDING', {
-        headers: {
-          Authorization: 1
-        }
-      },
-    );
-
-     if (response.ok) {
-    const data = await response.json();
-    props.setUser(data.map(request => {
+   
+    api_fetch.loadAdminRequests().then((data) => {
+      props.setUser(data.map(request => {
       
-      const a = request.date;
-      const b = [a.slice(0, 4), "-", a.slice(5, 7), "-", a.slice(8, 10)].join('');
-
-      return (
-        {
-          title: request.firstName + ' ' + request.lastName,
-          id: request.id,
-          type: request.type,
-          start: b,
-          end: null,
-          status: request.status
-      })
-    }))
-  } else {
-    if(response.status === 400) {
-      alert('error 400 GET DATA (UPCOMING REQUESTS)')
-   }
-      else if (response.status === 500) {
-         alert ('error 500 GET DATA (UPCOMING REQUESTS)')
-      }
-      else {
-         alert('error GET DATA (UPCOMING REQUESTS)')
-      }
-  }
-} catch (e) {
-  console.log(e)
-  alert('error catch GET DATA (UPCOMING REQUESTS)')
-  }    
+        const a = request.date;
+        const b = [a.slice(0, 4), "-", a.slice(5, 7), "-", a.slice(8, 10)].join('');
+  
+        return (
+          {
+            title: request.firstName + ' ' + request.lastName,
+            id: request.id,
+            type: request.type,
+            start: b,
+            end: null,
+            status: request.status
+        })
+      }))
+    }).catch(reason => {
+      alert(reason)
+    });
 }
 
+
+
   // send accepted request to server
   const acceptRequest = async (user) => {
-    try {
-    const response = await fetch('http://devcz.yoso.fi:8090/ymanager/user/requests?type=VACATION', {
-      headers: {
-        Authorization: 1,
-        'Content-Type': 'application/json',
-      },
-      method: 'PUT',
-      body: JSON.stringify({
-        id: user.id,
-        status: 'ACCEPTED',
-      }),
-    });
 
-    if (response.ok) {
-    const userProps = {
-      title: user.title,
-      id: 0,
-      type: user.type, 
-      start: user.start
-  }
-  //concat new request to current ones
-      props.setRequest((acceptedRequest) => acceptedRequest.concat(userProps))
-  //request accept button
-      props.setUser((pendingRequest) => pendingRequest.filter((item) => item !== user));
-
-    } else {
-      if(response.status === 400) {
-        alert('error 400 SEND ACCEPTED DATA (UPCOMING REQUESTS)')
-     }
-        else if (response.status === 500) {
-           alert ('error 500 SEND ACCEPTED DATA (UPCOMING REQUESTS)')
-        }
-        else {
-           alert('error SEND ACCEPTED DATA (UPCOMING REQUESTS)')
-        }
-    }
-  } catch (e) {
-    alert('error catch SEND ACCEPTED DATA (UPCOMING REQUESTS)')
+    const acceptedRequests = {
+      id: user.id,
+      status: 'ACCEPTED',
     }
+    
+    api_fetch.sendAcceptedRequest(acceptedRequests).then((data) => {
+      
+    const userProps = {
+          title: user.title,
+          id: 0,
+          type: user.type, 
+          start: user.start
+      }
+      //concat new request to current ones
+          props.setRequest((acceptedRequest) => acceptedRequest.concat(userProps))
+      //request accept button
+          props.setUser((pendingRequest) => pendingRequest.filter((item) => item !== user));
+    }).catch(response => {
+      alert(response)
+    })
   }
 
+ 
+
   //send rejected request to server
   const declineRequest = async (user) => {
-    try {
-      const response = await fetch('http://devcz.yoso.fi:8090/ymanager/user/requests?type=VACATION', {
-        headers: {
-          Authorization: 1,
-          'Content-Type': 'application/json',
-        },
-        method: 'PUT',
-        body: JSON.stringify({
-          id: user.id,
-          status: 'REJECTED',
-        }),
-      });
-
-    if (response.ok) {    
-  //request cancel button
-      props.setUser((acceptedRequest) => acceptedRequest.filter((item) => item !== user))
 
-    } else {
-      if(response.status === 400) {
-        alert('error 400 SEND REJECTED DATA (UPCOMING REQUESTS)')
-     }
-        else if (response.status === 500) {
-           alert ('error 500 SEND REJECTED DATA (UPCOMING REQUESTS)')
-        }
-        else {
-           alert('error SEND REJECTED DATA (UPCOMING REQUESTS)')
-        }
-    }
-  } catch (e) {
-    console.log(e)
-    alert('error catch SEND REJECTED DATA (UPCOMING REQUESTS)')
+    const rejectedRequest = {
+      id: user.id,
+      status: 'REJECTED',
     }
+
+    api_fetch.sendRejectedRequest(rejectedRequest).then((data) => {
+      //request cancel button
+      props.setUser((acceptedRequest) => acceptedRequest.filter((item) => item !== user))
+    }).catch(reason => {
+      alert(reason)
+    });
   }
 
   return (
diff --git a/client/src/YourRequests.js b/client/src/YourRequests.js
index 5ceebc8..99ac928 100644
--- a/client/src/YourRequests.js
+++ b/client/src/YourRequests.js
@@ -1,5 +1,6 @@
 import React, { useEffect } from 'react';
 import './App.css';
+import * as api_fetch from './api'
 
 function YourRequests(props) {
 
@@ -9,17 +10,9 @@ function YourRequests(props) {
 
   // get requests from server
   const getData = async () => {
-    try {
-      const response = await fetch(
-        'http://devcz.yoso.fi:8090/ymanager/user/6/calendar?from=2020/06/24&status=PENDING', {
-          headers: {
-            Authorization: 6
-          },
-        }
-      );
 
-    if (response.ok) {
-      const data = await response.json();
+    api_fetch.loadYourRequests().then((data) => {
+
       props.setUser(data.map(request => {
         const a = request.date;
         const b = [a.slice(0, 4), "-", a.slice(5, 7), "-", a.slice(8, 10)].join('');
@@ -34,23 +27,11 @@ function YourRequests(props) {
         }
       )
     }))
-    } else {
-      if(response.status === 400) {
-        alert('error 400 GET DATA (YOUR REQUEST)')
-     }
-        else if (response.status === 500) {
-           alert ('error 500 GET DATA (YOUR REQUEST)')
-        }
-        else {
-           alert('error GET DATA (YOUR REQUEST)')
-        }
-    }
-  } catch (e) {
-    console.log(e)
-    alert('error catch GET DATA (YOUR REQUEST)')
-  }
+    }).catch(reason => {
+      alert(reason)
+    });
 }
-        
+  
 
   return (
     <div className="offs-request column">
@@ -67,7 +48,7 @@ function YourRequests(props) {
                 <th>Status</th>    
               </tr>
               {props.userRequest.map(user => (
-              <tr>
+              <tr key={user.id}>
                 <td>{user.title}</td>
                 <td>{user.type}</td>    
                 <td>{user.end ? user.start + " - " + user.end : user.start}</td>
diff --git a/client/src/api.js b/client/src/api.js
index 9c0c615..d0e6d59 100644
--- a/client/src/api.js
+++ b/client/src/api.js
@@ -1,10 +1,12 @@
-// ******************** GET DATA APP getCurrentProfile, [userName, setUserName] ********************
+const http = 'http://devcz.yoso.fi:8090/ymanager';
+
+// ******************** GET DATA APP getCurrentProfile ********************
 
 export const getCurrentProfile = async () => {
 
     try {
     const response = await fetch(
-      'http://devcz.yoso.fi:8090/ymanager/users/current/profile', {
+      `${http}/users/current/profile`, {
         headers: {
           Authorization: 1
         }
@@ -22,18 +24,18 @@ export const getCurrentProfile = async () => {
     }
     } else {
         if(response.status === 400) {
-        alert('error 400 GET DATA APP (getCurrentProfile)')
-    }
+          throw 'error 400 GET DATA APP (getCurrentProfile)'
+        }
         else if (response.status === 500) {
-            alert ('error 500 GET DATA APP (getCurrentProfile)')
+          throw 'error 500 GET DATA APP (getCurrentProfile)'
         }
         else {
-            alert('error GET DATA APP (getCurrentProfile)')
+          throw 'error GET DATA APP (getCurrentProfile)'
         }
     }
 
 } catch (e) {
-  alert('error catch GET DATA APP (getCurrentProfile)')
+  throw 'error catch GET DATA APP (getCurrentProfile)'
   }
 }
 
@@ -41,7 +43,7 @@ export const getCurrentProfile = async () => {
 export const getUserCalendar = async (userName, fromDate ) => {
   try {
   const response = await fetch(
-    `http://devcz.yoso.fi:8090/ymanager/user/${userName.id}/calendar?from=${fromDate}&status=ACCEPTED&status=REJECTED`, {
+    `${http}/user/${userName.id}/calendar?from=${fromDate}&status=ACCEPTED&status=REJECTED`, {
       headers: {
         'Accept': 'application/json',
         Authorization: 6
@@ -66,18 +68,18 @@ export const getUserCalendar = async (userName, fromDate ) => {
     })
   })
 } else {
-  if(response.status === 400) {
-    alert('error 400 LOADING DATA (CALENDAR, EMPLOYEE)')
- }
+    if(response.status === 400) {
+      throw 'error 400 LOADING DATA (CALENDAR, EMPLOYEE)'
+    }
     else if (response.status === 500) {
-       alert ('error 500 LOADING DATA (CALENDAR, EMPLOYEE)')
+      throw 'error 500 LOADING DATA (CALENDAR, EMPLOYEE)'
     }
     else {
-       alert('error LOADING DATA (CALENDAR, EMPLOYEE)')
+      throw 'error LOADING DATA (CALENDAR, EMPLOYEE)'
     }
 }
 } catch (e) {
-  alert('error catch LOADING DATA (CALENDAR, EMPLOYEE)')
+  throw 'error catch LOADING DATA (CALENDAR, EMPLOYEE)'
 }
 }
 
@@ -107,88 +109,367 @@ export const getAdminCalendar = async () => {
       })
     })
   } else {
-    if(response.status === 400) {
-      alert('error 400 LOADING DATA (CALENDAR, EMPLOYER)')
-   }
+      if(response.status === 400) {
+        throw 'error 400 LOADING DATA (CALENDAR, EMPLOYER)'
+      }
       else if (response.status === 500) {
-         alert ('error 500 LOADING DATA (CALENDAR, EMPLOYER))')
+        throw 'error 500 LOADING DATA (CALENDAR, EMPLOYER))'
       }
       else {
-         alert('error LOADING DATA (CALENDAR, EMPLOYER)')
+        throw 'error LOADING DATA (CALENDAR, EMPLOYER)'
       }
-  }
+    }
   } catch (e) {
-    alert('error catch LOADING DATA (CALENDAR, EMPLOYER)')
+    throw 'error catch LOADING DATA (CALENDAR, EMPLOYER)'
   }
 }
 
 // ******************** ADD EVENT to CALENDAR - EMPLOYEE ********************
-export const addEvent = async (e) => {
-    e.preventDefault();
-
-  // setting an object
-    const newDate = whatDate.split("-").join("/");
-      
-    try {
+export async function addEventApi(dataAddEventEmployee) {
+try {
   // send accepted request to server
-      const response = await fetch('http://devcz.yoso.fi:8090/ymanager/user/calendar/create', {
+    const response = await fetch('http://devcz.yoso.fi:8090/ymanager/user/calendar/create', {
+      headers: {
+        Authorization: 6,
+        'Content-Type': 'application/json',
+      },
+      method: 'POST',
+  // object which is sent to server
+  body: JSON.stringify(dataAddEventEmployee),
+    });
+    if (response.ok) {
+      
+      const response = await fetch(
+      'http://devcz.yoso.fi:8090/ymanager/users/requests/vacation?status=PENDING', {
         headers: {
-          Authorization: 6,
-          'Content-Type': 'application/json',
+          Authorization: 1
         },
-        method: 'POST',
-  // object which is sent to server
-        body: JSON.stringify({
-          type: typeRadio === 'sickday' ? 'SICK_DAY' : 'VACATION',
-          date: newDate,
-          from: typeRadio === 'sickday' ? null : "00:00",
-          to: typeRadio === 'sickday' ? null : moment().startOf('day').add(whatTime, "hours").format("hh:mm"),
-        }),
       });
-      if (response.ok) {
+      const data = await response.json();
+      
+    return data.map(request => {
+      const a = request.date;
+      const b = [a.slice(0, 4), "-", a.slice(5, 7), "-", a.slice(8, 10)].join('');
 
-      const response = await fetch(
-        'http://devcz.yoso.fi:8090/ymanager/users/requests/vacation?status=PENDING', {
+      return (
+        {
+          title: request.firstName + ' ' + request.lastName,
+          id: request.id,
+          type: request.type,
+          start: b,
+          end: null,
+          status: request.status
+        })
+    })
+
+  } else {
+    
+    if(response.status === 400) {
+      throw 'error 400 ADD EVENT - EMPLOYEE'
+    }
+    else if (response.status === 500) {
+      throw 'error 500 ADD EVENT - EMPLOYEE'
+    }
+    else {
+      throw 'error ADD EVENT - EMPLOYEE'
+    }
+  }
+} catch (e) {
+    throw 'error catch ADD EVENT - EMPLOYEE'
+  }
+}
+      
+// ******************** ADD EVENT to CALENDAR - EMPLOYER ********************
+export async function addEventApiAdmin(dataAddEventAdmin) {
+  try {
+    // send accepted request to server
+        const response = await fetch('http://devcz.yoso.fi:8090/ymanager/user/calendar/create', {
           headers: {
-            Authorization: 1
+            Authorization: 1,
+            'Content-Type': 'application/json',
           },
+          method: 'POST',
+    // object which is sent to server
+          body: JSON.stringify(dataAddEventAdmin),
+        });
+        if (response.ok) {
+          return;
+    } else {
+      if(response.status === 400) {
+        throw('error 400 ADD EVENT ADMIN - EMPLOYER')
+     }
+        else if (response.status === 500) {
+           throw ('error 500 ADD EVENT ADMIN - EMPLOYER')
         }
-  
-       );
-      const data = await response.json();
+        else {
+           throw('error ADD EVENT ADMIN - EMPLOYER')
+        }
+    }
+  } catch (e) {
+      throw('error catch ADD EVENT ADMIN - EMPLOYER')
+    }
+}
 
-      return data.map(request => {
-        const a = request.date;
-        const b = [a.slice(0, 4), "-", a.slice(5, 7), "-", a.slice(8, 10)].join('');
+// ******************** GET DATA to OVERVIEW - EMPLOYER ********************
+export const getUsersOverview = async () => {
+  try {
+  const response = await fetch (
+     'http://devcz.yoso.fi:8090/ymanager/users', {
+      headers: {
+        Authorization: 1          }
+    }
+  );
   
-        return (
-          {
-            title: request.firstName + ' ' + request.lastName,
-            id: request.id,
-            type: request.type,
-            start: b,
-            end: null,
-            status: request.status
+if (response.ok) {
+
+  const data = await response.json();
+  return data.map(user => {
+
+     return (
+        {
+           name: user.firstName + ' ' + user.lastName,
+           id: user.id,
+           sickday: user.sickDayCount,
+           holiday: user.vacationCount,
+           role: user.role
         })
-      })
+  })
+}  else {
+      if(response.status === 400) {
+        throw 'error 400 GET DATA (OVERVIEW, EMPLOYER)'
+      }
+      else if (response.status === 500) {
+        throw 'error 500 GET DATA (OVERVIEW, EMPLOYER)'
+      }
+      else {
+        throw 'error GET DATA (OVERVIEW, EMPLOYER)'
+        }
+      }
+  } catch (e) {
+      throw 'error catch GET DATA (OVERVIEW, EMPLOYER)'
+  }
+}
 
-  } else {
+// ******************** SAVE DATA to OVERVIEW - EMPLOYER ********************
+export async function saveDataOverview(dataOverviewObject) {
+  try {
+    // send accepted request to server
+        const response = await fetch('http://devcz.yoso.fi:8090/ymanager/user/settings', {
+          headers: {
+            Authorization: 1,
+            'Content-Type': 'application/json',
+          },
+          method: 'PUT',
+ 
+    // object which is sent to server
+          body: JSON.stringify(dataOverviewObject),        
+        });
+        console.log(response.status)
+       if (response.status === 400) {
+        throw 'error 400 SAVE DATA (OVERVIEW, EMPLOYER)'
+          }
+      else if (response.status === 500) {
+        throw 'error 500 SAVE DATA (OVERVIEW, EMPLOYER)'
+      }
+      else if (!response.ok) {
+        throw 'error SAVE DATA (OVERVIEW, EMPLOYER)'
+      }
+
+  } catch (e) {
+    throw 'error catch SAVE DATA (OVERVIEW, EMPLOYER'
+  }
+}
+
+// ******************** LOAD DATA to SETTING - EMPLOYER ********************
+export const getSettingData = async () =>  {
+  try {
+    const response = await fetch(
+      'http://devcz.yoso.fi:8090/ymanager/settings', {
+        headers: {
+          Authorization: 1
+        }
+      });
+
+      if (response.ok) {
+      const data = await response.json();
+      return {
+        sickday: data.sickDayCount,
+      }
+    } else {
+        if(response.status === 400) {
+          throw 'error 400 LOADING DATA (SETTING, EMPLOYER)'
+        }
+        else if (response.status === 500) {
+           throw 'error 500 LOADING DATA (SETTING, EMPLOYER)'
+        }
+        else {
+           throw 'error LOADING DATA (SETTING, EMPLOYER)'
+        }
+      }
+  } catch (e) {
+    throw 'error catch LOADING DATA (SETTING, EMPLOYER)'
+    }
+}
+
+// ******************** SAVE DATA to SETTING - EMPLOYER ********************
+export async function saveDataSetting(dataSettingObject) {
+  try {
+    const response = await fetch('http://devcz.yoso.fi:8090/ymanager/settings', {
+      headers: {
+        'Authorization': 6,
+        'Content-Type': 'application/json'
+      },
+      method: 'POST',
+      body: JSON.stringify(dataSettingObject),
+    });
+
+    switch (response.status) {
+      case 200:
+        throw '...'
+      case 500:
+        throw ''
+      default:
+        throw response.statusText
+
+    }
 
     if(response.status === 400) {
-    alert('error 400 ADD EVENT - EMPLOYEE')
- }
+      throw 'error 400 SAVE DATA (OVERVIEW, EMPLOYER)'
+    }
     else if (response.status === 500) {
-       alert ('error 500 ADD EVENT - EMPLOYEE')
+      throw 'error 500 SAVE DATA (OVERVIEW, EMPLOYER)'
     }
-    else {
-       alert('error ADD EVENT - EMPLOYEE')
+    else if (!response.ok) {
+      throw 'error SAVE DATA (OVERVIEW, EMPLOYER)'
+      }
+  } catch (e) {
+      throw 'error catch SAVE DATA (OVERVIEW, EMPLOYER)'
     }
-    
+}
+
+// ****************** LOAD DATA to YOUR REQUESTS - EMPLOYEE ******************
+
+export async function loadYourRequests() {
+  try {
+    const response = await fetch(
+      'http://devcz.yoso.fi:8090/ymanager/user/6/calendar?from=2020/06/24&status=PENDING', {
+        headers: {
+          Authorization: 6
+        },
+      }
+    );
+
+  if (response.ok) {
+    const data = await response.json();
+    return data;
+  } else {
+    if(response.status === 400) {
+      alert('error 400 GET DATA (YOUR REQUEST)')
+   }
+      else if (response.status === 500) {
+         alert ('error 500 GET DATA (YOUR REQUEST)')
+      }
+      else {
+         alert('error GET DATA (YOUR REQUEST)')
+      }
+  }
+} catch (e) {
+  console.log(e)
+  alert('error catch GET DATA (YOUR REQUEST)')
   }
-    } catch (e) {
-      alert('error catch ADD EVENT - EMPLOYEE')
+}
+
+// ****************** LOAD DATA - UPCOMING REQUESTS - EMPLOYER ******************
+export async function loadAdminRequests() {
+  try {
+    const response = await fetch(
+      'http://devcz.yoso.fi:8090/ymanager/users/requests/vacation?status=PENDING', {
+        headers: {
+          Authorization: 1
+        }
+      },
+    );
+
+     if (response.ok) {
+    const data = await response.json();
+      return data;
+  } else {
+    if(response.status === 400) {
+      alert('error 400 GET DATA (UPCOMING REQUESTS)')
+   }
+      else if (response.status === 500) {
+         alert ('error 500 GET DATA (UPCOMING REQUESTS)')
+      }
+      else {
+         alert('error GET DATA (UPCOMING REQUESTS)')
+      }
     }
+} catch (e) {
+  alert('error catch GET DATA (UPCOMING REQUESTS)')
+  } 
+}
+
+// ************** SEND ACCEPTED DATA - UPCOMING REQUESTS - EMPLOYER **************
+export async function sendAcceptedRequest(acceptedRequests) {
+  try {
+    const response = await fetch('http://devcz.yoso.fi:8090/ymanager/user/requests?type=VACATION', {
+      headers: {
+        Authorization: 1,
+        'Content-Type': 'application/json',
+      },
+      method: 'PUT',
+      body: JSON.stringify(acceptedRequests),
+    });
+
+    if (response.ok) {
+    return;
+
+    } else {
+      if(response.status === 400) {
+        alert('error 400 SEND ACCEPTED DATA (UPCOMING REQUESTS)')
+     }
+        else if (response.status === 500) {
+           alert ('error 500 SEND ACCEPTED DATA (UPCOMING REQUESTS)')
+        }
+        else {
+           alert('error SEND ACCEPTED DATA (UPCOMING REQUESTS)')
+        }
+    }
+  } catch (e) {
+    alert('error catch SEND ACCEPTED DATA (UPCOMING REQUESTS)')
+    }
+}
+
+// ************** SEND REJECTED DATA - UPCOMING REQUESTS - EMPLOYER **************
+
+export async function sendRejectedRequest(rejectedRequest) {
+  try {
+    const response = await fetch('http://devcz.yoso.fi:8090/ymanager/user/requests?type=VACATION', {
+      headers: {
+        Authorization: 1,
+        'Content-Type': 'application/json',
+      },
+      method: 'PUT',
+      body: JSON.stringify(rejectedRequest),
+    });
+
+  if (response.ok) {    
+    return;
+
+  } else {
+    if(response.status === 400) {
+      alert('error 400 SEND REJECTED DATA (UPCOMING REQUESTS)')
+   }
+      else if (response.status === 500) {
+         alert ('error 500 SEND REJECTED DATA (UPCOMING REQUESTS)')
+      }
+      else {
+         alert('error SEND REJECTED DATA (UPCOMING REQUESTS)')
+      }
+  }
+} catch (e) {
+  alert('error catch SEND REJECTED DATA (UPCOMING REQUESTS)')
+  }
+}
+
 
-    setOpen(false)}
-    
-//
\ No newline at end of file
