| 1 | import axios from "axios";
|
|---|
| 2 |
|
|---|
| 3 | const usersRoute = "/users";
|
|---|
| 4 |
|
|---|
| 5 | const UserRole = {
|
|---|
| 6 | Potrosuvac: 'USER',
|
|---|
| 7 | Vozac: 'DRIVER',
|
|---|
| 8 | Admin: 'ADMIN',
|
|---|
| 9 | Menager: 'MANAGER'
|
|---|
| 10 | }
|
|---|
| 11 |
|
|---|
| 12 | const BasicAuth = (username, password) => {
|
|---|
| 13 | return 'Basic ' + window.btoa(username + ":" + password);
|
|---|
| 14 | }
|
|---|
| 15 |
|
|---|
| 16 | const 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 |
|
|---|
| 27 | const RegisterUser = (userForm) => {
|
|---|
| 28 | return axios.post(`${usersRoute}`, userForm);
|
|---|
| 29 | }
|
|---|
| 30 |
|
|---|
| 31 | const 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 |
|
|---|
| 40 | const GetUser = (username) => {
|
|---|
| 41 | return axios.get(`${usersRoute}/${username}`);
|
|---|
| 42 | }
|
|---|
| 43 |
|
|---|
| 44 | const GetAllUsers = () => {
|
|---|
| 45 | return axios.get(`${usersRoute}`);
|
|---|
| 46 | }
|
|---|
| 47 |
|
|---|
| 48 | const 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 |
|
|---|
| 57 | const 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 |
|
|---|
| 66 | export {
|
|---|
| 67 | UserRole,
|
|---|
| 68 | LoginUser,
|
|---|
| 69 | RegisterUser,
|
|---|
| 70 | GetUser,
|
|---|
| 71 | GetAllUsers,
|
|---|
| 72 | GetUserById,
|
|---|
| 73 | UpdateUser,
|
|---|
| 74 | GetInactiveManagers,
|
|---|
| 75 | BasicAuth
|
|---|
| 76 | } |
|---|