| 1 | import axios from "axios";
|
|---|
| 2 |
|
|---|
| 3 | const vehicleRoute = "/vehicles";
|
|---|
| 4 |
|
|---|
| 5 | const GetAllVehicles = async () => {
|
|---|
| 6 | try {
|
|---|
| 7 | const response = await axios.get(vehicleRoute);
|
|---|
| 8 | return response.data;
|
|---|
| 9 | } catch (error) {
|
|---|
| 10 | console.error("Error fetching", error);
|
|---|
| 11 | }
|
|---|
| 12 | };
|
|---|
| 13 |
|
|---|
| 14 | const GetVehicle = async (id) => {
|
|---|
| 15 | try {
|
|---|
| 16 | const response = await axios.get(`${vehicleRoute}/${id}`);
|
|---|
| 17 | return response.data;
|
|---|
| 18 | } catch (error) {
|
|---|
| 19 | console.error("Error fetching", error);
|
|---|
| 20 | }
|
|---|
| 21 | };
|
|---|
| 22 |
|
|---|
| 23 | const GetVehicleByDriverId = async (driverId) => {
|
|---|
| 24 | try {
|
|---|
| 25 | const response = await axios.get(`${vehicleRoute}/driver/${driverId}`);
|
|---|
| 26 | return response.data;
|
|---|
| 27 | } catch (error) {
|
|---|
| 28 | console.error("Error fetching", error);
|
|---|
| 29 | }
|
|---|
| 30 | };
|
|---|
| 31 |
|
|---|
| 32 | const CreateVehicle = async (formData) => {
|
|---|
| 33 | try {
|
|---|
| 34 | const response = await axios.post(`${vehicleRoute}`, formData);
|
|---|
| 35 | return response.data;
|
|---|
| 36 | } catch (error) {
|
|---|
| 37 | console.error("Error occured", error);
|
|---|
| 38 | }
|
|---|
| 39 | };
|
|---|
| 40 |
|
|---|
| 41 | const UpdateVehicle = async (id, formData) => {
|
|---|
| 42 | try {
|
|---|
| 43 | const response = await axios.post(`${vehicleRoute}/${id}`, formData);
|
|---|
| 44 | return response.data;
|
|---|
| 45 | } catch (error) {
|
|---|
| 46 | console.error("Error occured", error);
|
|---|
| 47 | }
|
|---|
| 48 | };
|
|---|
| 49 |
|
|---|
| 50 | const DeleteVehicle = async (id) => {
|
|---|
| 51 | try {
|
|---|
| 52 | const response = await axios.delete(`${vehicleRoute}/${id}`);
|
|---|
| 53 | return response.data;
|
|---|
| 54 | } catch (error) {
|
|---|
| 55 | console.error("Error occured", error);
|
|---|
| 56 | }
|
|---|
| 57 | };
|
|---|
| 58 |
|
|---|
| 59 |
|
|---|
| 60 | export {GetAllVehicles, GetVehicle, GetVehicleByDriverId, CreateVehicle, UpdateVehicle, DeleteVehicle} |
|---|