source: frontend/src/services/user-service.jsx@ badbc79

Last change on this file since badbc79 was badbc79, checked in by Luka Cheshlarov <luka.cheshlarov@…>, 20 months ago

Initial commit

  • Property mode set to 100644
File size: 1.7 KB
Line 
1import axios from "axios";
2
3const usersRoute = "/users";
4
5const UserRole = {
6 Potrosuvac: 'USER',
7 Vozac: 'DRIVER',
8 Admin: 'ADMIN',
9 Menager: 'MANAGER'
10}
11
12const BasicAuth = (username, password) => {
13 return 'Basic ' + window.btoa(username + ":" + password);
14}
15
16const LoginUser = async (loginForm) => {
17 try {
18 const response = await axios.post(`${usersRoute}/login`, loginForm);
19 axios.defaults.headers.common['Authorization'] = BasicAuth(response.data.username, response.data.password);
20
21 return response.data;
22 } catch (error) {
23 console.error("Error fetching restaurants:", error);
24 }
25}
26
27const RegisterUser = (userForm) => {
28 return axios.post(`${usersRoute}`, userForm);
29}
30
31const UpdateUser = async (id, loginForm) => {
32 try {
33 const response = await axios.post(`${usersRoute}/${id}`, loginForm);
34 return response.data;
35 } catch (error) {
36 console.error("An Error Occured:", error);
37 }
38}
39
40const GetUser = (username) => {
41 return axios.get(`${usersRoute}/${username}`);
42}
43
44const GetAllUsers = () => {
45 return axios.get(`${usersRoute}`);
46}
47
48const GetUserById = async (id) => {
49 try {
50 const response = await axios.get(`${usersRoute}/${id}`);
51 return response.data;
52 } catch (error) {
53 console.error("Error fetching restaurants:", error);
54 }
55}
56
57const GetInactiveManagers = async () => {
58 try {
59 const response = await axios.get(`${usersRoute}/managers/inactive`);
60 return response.data;
61 } catch (error) {
62 console.error("Error fetching restaurants:", error);
63 }
64}
65
66export {
67 UserRole,
68 LoginUser,
69 RegisterUser,
70 GetUser,
71 GetAllUsers,
72 GetUserById,
73 UpdateUser,
74 GetInactiveManagers,
75 BasicAuth
76}
Note: See TracBrowser for help on using the repository browser.