66 defaultCoachingRelationshipWithUserNames ,
77 defaultCoachingRelationshipsWithUserNames ,
88 isCoachingRelationshipWithUserNames ,
9- isCoachingRelationshipWithUserNamesArray
9+ isCoachingRelationshipWithUserNamesArray ,
10+ parseCoachingRelationshipWithUserNames ,
1011} from "@/types/coaching_relationship_with_user_names" ;
1112import { Id } from "@/types/general" ;
1213import { AxiosError , AxiosResponse } from "axios" ;
@@ -17,39 +18,51 @@ export const fetchCoachingRelationshipWithUserNames = async (
1718) : Promise < CoachingRelationshipWithUserNames > => {
1819 const axios = require ( "axios" ) ;
1920
20- var relationship : CoachingRelationshipWithUserNames = defaultCoachingRelationshipWithUserNames ( ) ;
21+ var relationship : CoachingRelationshipWithUserNames =
22+ defaultCoachingRelationshipWithUserNames ( ) ;
2123 var err : string = "" ;
2224
2325 const data = await axios
24- . get ( `http://localhost:4000/organizations/${ organization_id } /coaching_relationships/${ relationship_id } ` , {
25- withCredentials : true ,
26- setTimeout : 5000 , // 5 seconds before timing out trying to log in with the backend
27- headers : {
28- "X-Version" : "0.0.1" ,
29- } ,
30- } )
26+ . get (
27+ `http://localhost:4000/organizations/${ organization_id } /coaching_relationships/${ relationship_id } ` ,
28+ {
29+ withCredentials : true ,
30+ setTimeout : 5000 , // 5 seconds before timing out trying to log in with the backend
31+ headers : {
32+ "X-Version" : "0.0.1" ,
33+ } ,
34+ }
35+ )
3136 . then ( function ( response : AxiosResponse ) {
3237 // handle success
33- if ( isCoachingRelationshipWithUserNames ( response . data . data ) ) {
34- relationship = response . data . data ;
38+ const relationshipData = response . data . data ;
39+ if ( isCoachingRelationshipWithUserNames ( relationshipData ) ) {
40+ relationship = parseCoachingRelationshipWithUserNames ( relationshipData ) ;
3541 }
3642 } )
3743 . catch ( function ( error : AxiosError ) {
3844 // handle error
3945 console . error ( error . response ?. status ) ;
4046 if ( error . response ?. status == 401 ) {
41- err = "Retrieval of CoachingRelationshipWithUserNames failed: unauthorized." ;
47+ err =
48+ "Retrieval of CoachingRelationshipWithUserNames failed: unauthorized." ;
4249 } else if ( error . response ?. status == 500 ) {
43- err = "Retrieval of CoachingRelationshipWithUserNames failed, system error: " + error . response . data ;
50+ err =
51+ "Retrieval of CoachingRelationshipWithUserNames failed, system error: " +
52+ error . response . data ;
4453 } else {
45- err = `Retrieval of CoachingRelationshipWithUserNames(` + relationship_id + `) failed: ` + error . response ?. data ;
54+ err =
55+ `Retrieval of CoachingRelationshipWithUserNames(` +
56+ relationship_id +
57+ `) failed: ` +
58+ error . response ?. data ;
4659 }
4760 } ) ;
4861
49- if ( err ) {
50- console . error ( err ) ;
51- throw err ;
52- }
62+ if ( err ) {
63+ console . error ( err ) ;
64+ throw err ;
65+ }
5366
5467 return relationship ;
5568} ;
@@ -59,40 +72,53 @@ export const fetchCoachingRelationshipsWithUserNames = async (
5972) : Promise < [ CoachingRelationshipWithUserNames [ ] , string ] > => {
6073 const axios = require ( "axios" ) ;
6174
62- var relationships : CoachingRelationshipWithUserNames [ ] = defaultCoachingRelationshipsWithUserNames ( ) ;
75+ var relationships : CoachingRelationshipWithUserNames [ ] =
76+ defaultCoachingRelationshipsWithUserNames ( ) ;
6377 var err : string = "" ;
6478
6579 const data = await axios
66- . get ( `http://localhost:4000/organizations/${ organizationId } /coaching_relationships` , {
67- withCredentials : true ,
68- setTimeout : 5000 , // 5 seconds before timing out trying to log in with the backend
69- headers : {
70- "X-Version" : "0.0.1" ,
71- } ,
72- } )
80+ . get (
81+ `http://localhost:4000/organizations/${ organizationId } /coaching_relationships` ,
82+ {
83+ withCredentials : true ,
84+ setTimeout : 5000 , // 5 seconds before timing out trying to log in with the backend
85+ headers : {
86+ "X-Version" : "0.0.1" ,
87+ } ,
88+ }
89+ )
7390 . then ( function ( response : AxiosResponse ) {
7491 // handle success
7592 console . debug ( response ) ;
7693 if ( isCoachingRelationshipWithUserNamesArray ( response . data . data ) ) {
7794 relationships = response . data . data ;
7895 console . debug (
79- `CoachingRelationshipsWithUserNames: ` + coachingRelationshipsWithUserNamesToString ( relationships ) + `.`
96+ `CoachingRelationshipsWithUserNames: ` +
97+ coachingRelationshipsWithUserNamesToString ( relationships ) +
98+ `.`
8099 ) ;
81100 }
82101 } )
83102 . catch ( function ( error : AxiosError ) {
84103 // handle error
85104 console . error ( error . response ?. status ) ;
86105 if ( error . response ?. status == 401 ) {
87- console . error ( "Retrieval of CoachingRelationshipsWithUserNames failed: unauthorized." ) ;
88- err = "Retrieval of CoachingRelationshipsWithUserNames failed: unauthorized." ;
106+ console . error (
107+ "Retrieval of CoachingRelationshipsWithUserNames failed: unauthorized."
108+ ) ;
109+ err =
110+ "Retrieval of CoachingRelationshipsWithUserNames failed: unauthorized." ;
89111 } else {
90112 console . log ( error ) ;
91113 console . error (
92- `Retrieval of CoachingRelationshipsWithUserNames by organization Id (` + organizationId + `) failed.`
114+ `Retrieval of CoachingRelationshipsWithUserNames by organization Id (` +
115+ organizationId +
116+ `) failed.`
93117 ) ;
94118 err =
95- `Retrieval of CoachingRealtionshipsWithUserNames by organization Id (` + organizationId + `) failed.` ;
119+ `Retrieval of CoachingRealtionshipsWithUserNames by organization Id (` +
120+ organizationId +
121+ `) failed.` ;
96122 }
97123 } ) ;
98124
0 commit comments