1- import axios , { type AxiosResponse } from 'axios' ;
1+ import axios , { type AxiosResponse } from 'axios'
22
33const publicAxiosApi = axios . create ( {
44 baseURL : '/api/v1' ,
55 timeout : 10000 ,
6- headers : { 'content-type' : 'application/json' }
6+ headers : { 'content-type' : 'application/json' }
77} )
88
99const protectedAxiosApi = axios . create ( {
1010 baseURL : '/api/v1/protected' ,
1111 timeout : 10000 ,
12- headers : { 'content-type' : 'application/json' }
12+ headers : { 'content-type' : 'application/json' }
1313} )
1414
1515export default {
@@ -23,75 +23,99 @@ export default {
2323 return protectedAxiosApi . get ( '/' , { withCredentials : true } )
2424 } ,
2525 logout ( ) : Promise < AxiosResponse > {
26- console . log ( " Logging out" )
26+ console . log ( ' Logging out' )
2727 return publicAxiosApi . post ( '/logout' , { } , { withCredentials : true } )
2828 } ,
2929
3030 getUserStatistics ( id ?: string ) : Promise < AxiosResponse > {
31- const data = id ? { id } : { } ;
32- const config = { withCredentials : true } ;
33- return protectedAxiosApi . post ( '/user/statistics' , data , config ) ;
31+ const data = id ? { id } : { }
32+ const config = { withCredentials : true }
33+ return protectedAxiosApi . post ( '/user/statistics' , data , config )
3434 } ,
3535 getActivityFeed ( ) : Promise < AxiosResponse > {
36- return protectedAxiosApi . get ( '/activites' , { withCredentials : true } ) ;
36+ return protectedAxiosApi . get ( '/activites' , { withCredentials : true } )
3737 } ,
3838 getUserImage ( id ?: string ) : Promise < AxiosResponse > {
39- const config = { withCredentials : true } ;
40- const data = id ? { user_id : id } : { } ;
41- return protectedAxiosApi . post ( '/user/image' , data , config ) ;
39+ const config = { withCredentials : true }
40+ const data = id ? { user_id : id } : { }
41+ return protectedAxiosApi . post ( '/user/image' , data , config )
4242 } ,
4343 getUser ( username : string ) : Promise < AxiosResponse > {
44- return protectedAxiosApi . get ( `/user/${ username } ` , { withCredentials : true } ) ;
44+ return protectedAxiosApi . get ( `/user/${ username } ` , { withCredentials : true } )
4545 } ,
4646 getMyself ( ) : Promise < AxiosResponse > {
47- return protectedAxiosApi . get ( '/user' , { withCredentials : true } ) ;
47+ return protectedAxiosApi . get ( '/user' , { withCredentials : true } )
4848 } ,
4949 getChatHistory ( ) : Promise < AxiosResponse > {
50- return protectedAxiosApi . get ( '/chat/history' , { withCredentials : true } ) ;
50+ return protectedAxiosApi . get ( '/chat/history' , { withCredentials : true } )
5151 } ,
5252 getPastRuns ( ) : Promise < AxiosResponse > {
53- return protectedAxiosApi . get ( '/runs' , { withCredentials : true } ) ;
53+ return protectedAxiosApi . get ( '/runs' , { withCredentials : true } )
5454 } ,
5555 deletePastRun ( id : string ) : Promise < AxiosResponse > {
56- return protectedAxiosApi . delete ( `/runs/${ id } ` , { withCredentials : true } ) ;
56+ return protectedAxiosApi . delete ( `/runs/${ id } ` , { withCredentials : true } )
5757 } ,
5858 savePlannedRun ( route : string , name : string , distance : number ) : Promise < AxiosResponse > {
59- return protectedAxiosApi . post ( '/runs/plan' , { route, name, distance } , { withCredentials : true } ) ;
59+ return protectedAxiosApi . post (
60+ '/runs/plan' ,
61+ { route, name, distance } ,
62+ { withCredentials : true }
63+ )
6064 } ,
6165 getPlannedRuns ( ) : Promise < AxiosResponse > {
62- return protectedAxiosApi . get ( '/runs/plan' , { withCredentials : true } ) ;
66+ return protectedAxiosApi . get ( '/runs/plan' , { withCredentials : true } )
6367 } ,
6468 deletePlannedRun ( id : string ) : Promise < AxiosResponse > {
65- return protectedAxiosApi . delete ( `/runs/plan/${ id } ` , { withCredentials : true } ) ;
66- } ,
67- getChallenges ( ) : Promise < AxiosResponse > {
68- return protectedAxiosApi . get ( '/challenges/new' , { withCredentials : true } ) ;
69- } ,
70- completeChallenge ( challengeId : string , rocketPoints : number ) : Promise < AxiosResponse > {
71- return protectedAxiosApi . post ( '/challenges/complete' , { challenge_id : challengeId , rocket_points : rocketPoints } , { withCredentials : true } ) ;
72- } ,
73- getChallengeProgress ( ) : Promise < AxiosResponse > {
74- return protectedAxiosApi . get ( '/challenges/progress' , { withCredentials : true } ) ;
75- } ,
76- getFriends ( ) : Promise < AxiosResponse > {
77- return protectedAxiosApi . get ( '/friends' , { withCredentials : true } ) ;
78- } ,
79- inviteFriendToChallenge ( challengeId : string , friendId : string ) : Promise < AxiosResponse > {
80- return protectedAxiosApi . post ( '/challenges/invite' , { challenge_id : challengeId , friend_id : friendId } , { withCredentials : true } ) ;
81- } ,
69+ return protectedAxiosApi . delete ( `/runs/plan/${ id } ` , { withCredentials : true } )
70+ } ,
71+ getChallenges ( ) : Promise < AxiosResponse > {
72+ return protectedAxiosApi . get ( '/challenges/new' , { withCredentials : true } )
73+ } ,
74+ completeChallenge ( challengeId : string , rocketPoints : number ) : Promise < AxiosResponse > {
75+ return protectedAxiosApi . post (
76+ '/challenges/complete' ,
77+ { challenge_id : challengeId , rocket_points : rocketPoints } ,
78+ { withCredentials : true }
79+ )
80+ } ,
81+ getChallengeProgress ( ) : Promise < AxiosResponse > {
82+ return protectedAxiosApi . get ( '/challenges/progress' , { withCredentials : true } )
83+ } ,
84+ getFriends ( ) : Promise < AxiosResponse > {
85+ return protectedAxiosApi . get ( '/friends' , { withCredentials : true } )
86+ } ,
87+ inviteFriendToChallenge ( challengeId : string , friendId : string ) : Promise < AxiosResponse > {
88+ return protectedAxiosApi . post (
89+ '/challenges/invite' ,
90+ { challenge_id : challengeId , friend_id : friendId } ,
91+ { withCredentials : true }
92+ )
93+ } ,
8294 getFollowing ( id : string ) : Promise < AxiosResponse > {
83- return protectedAxiosApi . get ( `/following/${ id } ` , { withCredentials : true } ) ;
95+ return protectedAxiosApi . get ( `/following/${ id } ` , { withCredentials : true } )
8496 } ,
8597 getFollowers ( id : string ) : Promise < AxiosResponse > {
86- return protectedAxiosApi . get ( `/followers/${ id } ` , { withCredentials : true } ) ;
87- } ,
88- addFriend ( friendName : string ) : Promise < AxiosResponse > {
89- return protectedAxiosApi . post ( '/friends/add' , { friend_name : friendName } , { withCredentials : true } ) ;
90- } ,
91- deleteFriend ( friendName : string ) : Promise < AxiosResponse > {
92- return protectedAxiosApi . delete ( `/friends/${ encodeURIComponent ( friendName ) } ` , { withCredentials : true } ) ;
93- } ,
94- getAllUsers ( ) : Promise < AxiosResponse > {
95- return protectedAxiosApi . get ( '/users' , { withCredentials : true } ) ;
96- } ,
98+ return protectedAxiosApi . get ( `/followers/${ id } ` , { withCredentials : true } )
99+ } ,
100+ getRankedUsers ( ) : Promise < AxiosResponse > {
101+ return protectedAxiosApi . get ( '/ranking/users' , { withCredentials : true } )
102+ } ,
103+ getRankedFriends ( ) : Promise < AxiosResponse > {
104+ return protectedAxiosApi . get ( '/ranking/friends' , { withCredentials : true } )
105+ } ,
106+ addFriend ( friendName : string ) : Promise < AxiosResponse > {
107+ return protectedAxiosApi . post (
108+ '/friends/add' ,
109+ { friend_name : friendName } ,
110+ { withCredentials : true }
111+ )
112+ } ,
113+ deleteFriend ( friendName : string ) : Promise < AxiosResponse > {
114+ return protectedAxiosApi . delete ( `/friends/${ encodeURIComponent ( friendName ) } ` , {
115+ withCredentials : true
116+ } )
117+ } ,
118+ getAllUsers ( ) : Promise < AxiosResponse > {
119+ return protectedAxiosApi . get ( '/users' , { withCredentials : true } )
120+ }
97121}
0 commit comments