1
- import axios from 'axios' ;
2
- import Cookies from 'js-cookie' ;
3
- import { API_URL } from '../config' ;
4
-
5
- export const getTrips = async ( ) => {
6
- const res = await fetch ( `${ API_URL } /trips` , {
7
- method : 'GET' ,
8
- credentials : 'include' ,
9
- headers : { 'Content-Type' : 'application/json' } ,
10
- } ) ;
11
- const data = await res . json ( ) ;
12
- return data ;
13
- } ;
1
+ import axios from '../config/axios' ;
14
2
15
3
export const getTripsWithQuery = async ( query : any ) => {
16
- return axios . get ( `${ API_URL } /trips` , {
17
- params : query ,
18
- headers : {
19
- 'Content-Type' : 'application/json' ,
20
- Accept : 'application/json' ,
21
- } ,
22
- } ) ;
4
+ return axios . get ( '/trips' , { params : query } ) ;
23
5
} ;
24
6
25
7
export const getRandomTrips = async (
26
8
type : 'videos' | 'stories' | 'photos' | '' = ''
27
- ) => {
28
- return axios . get ( `${ API_URL } /trips/latest` , {
29
- params : type ? { [ type ] : true } : { } ,
30
- headers : {
31
- 'Content-Type' : 'application/json' ,
32
- Authorization : `Bearer ${ Cookies . get ( 'authToken' ) } ` ,
33
- Accept : 'application/json' ,
34
- } ,
35
- } ) ;
36
- } ;
9
+ ) => axios . get ( '/trips/latest' , { params : type ? { [ type ] : true } : { } } ) ;
37
10
38
- export const getTrip = async ( trip_id : any ) => {
39
- return axios . get ( `${ API_URL } /trips/${ trip_id } ` , {
40
- headers : {
41
- 'Content-Type' : 'application/json' ,
42
- Authorization : `Bearer ${ Cookies . get ( 'authToken' ) } ` ,
43
- Accept : 'application/json' ,
44
- } ,
45
- } ) ;
46
- } ;
11
+ export const gettrip = async ( trip_id : any ) => axios . get ( `/trips/${ trip_id } ` ) ;
47
12
48
13
export const getTripsByLocation = async (
49
14
north_lat : number ,
50
15
south_lat : number ,
51
16
west_lng : number ,
52
17
east_lng : number
53
18
) =>
54
- axios . get ( `${ API_URL } /trips` , {
19
+ axios . get ( `/trips` , {
55
20
params : {
56
21
q : {
57
22
from_lat_gt : south_lat ,
@@ -60,47 +25,12 @@ export const getTripsByLocation = async (
60
25
from_lng_lt : east_lng ,
61
26
} ,
62
27
} ,
63
- headers : {
64
- 'Content-Type' : 'application/json' ,
65
- Accept : 'application/json' ,
66
- } ,
67
28
} ) ;
68
29
69
- export const createTrip = ( payload : any ) => {
70
- return axios . post ( `${ API_URL } /trips` , payload , {
71
- headers : {
72
- 'Content-Type' : 'application/json' ,
73
- Accept : 'application/json' ,
74
- Authorization : `Bearer ${ Cookies . get ( 'authToken' ) } ` ,
75
- } ,
76
- } ) ;
77
- } ;
78
-
79
- export const deleteTrip = ( id : number ) => {
80
- return axios . delete ( `${ API_URL } /trips/${ id } ` , {
81
- headers : {
82
- Accept : 'application/json' ,
83
- Authorization : `Bearer ${ Cookies . get ( 'authToken' ) } ` ,
84
- } ,
85
- } ) ;
86
- } ;
87
-
88
- export const updateTrip = ( payload : any ) => {
89
- return axios . put ( `${ API_URL } /trips/${ payload . id } ` , payload , {
90
- headers : {
91
- 'Content-Type' : 'application/json' ,
92
- Accept : 'application/json' ,
93
- Authorization : `Bearer ${ Cookies . get ( 'authToken' ) } ` ,
94
- } ,
95
- } ) ;
96
- } ;
97
-
98
- export const updateRide = ( payload : any ) => {
99
- return axios . patch ( `${ API_URL } /rides/${ payload . id } ` , payload , {
100
- headers : {
101
- 'Content-Type' : 'multipart/form-data' ,
102
- Accept : 'application/json' ,
103
- Authorization : `Bearer ${ Cookies . get ( 'authToken' ) } ` ,
104
- } ,
105
- } ) ;
106
- } ;
30
+ export const getTrip = async ( trip_id : any ) => axios . get ( `/trips/${ trip_id } ` ) ;
31
+ export const createTrip = ( payload : any ) => axios . post ( `/trips` , payload ) ;
32
+ export const deleteTrip = ( id : number ) => axios . delete ( `/trips/${ id } ` ) ;
33
+ export const updateTrip = ( payload : any ) =>
34
+ axios . put ( `/trips/${ payload . id } ` , payload ) ;
35
+ export const updateRide = ( payload : any ) =>
36
+ axios . patch ( `/rides/${ payload . id } ` , payload ) ;
0 commit comments