6
6
defaultCoachingRelationshipWithUserNames ,
7
7
defaultCoachingRelationshipsWithUserNames ,
8
8
isCoachingRelationshipWithUserNames ,
9
- isCoachingRelationshipWithUserNamesArray
9
+ isCoachingRelationshipWithUserNamesArray ,
10
+ parseCoachingRelationshipWithUserNames ,
10
11
} from "@/types/coaching_relationship_with_user_names" ;
11
12
import { Id } from "@/types/general" ;
12
13
import { AxiosError , AxiosResponse } from "axios" ;
@@ -17,39 +18,51 @@ export const fetchCoachingRelationshipWithUserNames = async (
17
18
) : Promise < CoachingRelationshipWithUserNames > => {
18
19
const axios = require ( "axios" ) ;
19
20
20
- var relationship : CoachingRelationshipWithUserNames = defaultCoachingRelationshipWithUserNames ( ) ;
21
+ var relationship : CoachingRelationshipWithUserNames =
22
+ defaultCoachingRelationshipWithUserNames ( ) ;
21
23
var err : string = "" ;
22
24
23
25
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
+ )
31
36
. then ( function ( response : AxiosResponse ) {
32
37
// 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 ) ;
35
41
}
36
42
} )
37
43
. catch ( function ( error : AxiosError ) {
38
44
// handle error
39
45
console . error ( error . response ?. status ) ;
40
46
if ( error . response ?. status == 401 ) {
41
- err = "Retrieval of CoachingRelationshipWithUserNames failed: unauthorized." ;
47
+ err =
48
+ "Retrieval of CoachingRelationshipWithUserNames failed: unauthorized." ;
42
49
} 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 ;
44
53
} 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 ;
46
59
}
47
60
} ) ;
48
61
49
- if ( err ) {
50
- console . error ( err ) ;
51
- throw err ;
52
- }
62
+ if ( err ) {
63
+ console . error ( err ) ;
64
+ throw err ;
65
+ }
53
66
54
67
return relationship ;
55
68
} ;
@@ -59,40 +72,53 @@ export const fetchCoachingRelationshipsWithUserNames = async (
59
72
) : Promise < [ CoachingRelationshipWithUserNames [ ] , string ] > => {
60
73
const axios = require ( "axios" ) ;
61
74
62
- var relationships : CoachingRelationshipWithUserNames [ ] = defaultCoachingRelationshipsWithUserNames ( ) ;
75
+ var relationships : CoachingRelationshipWithUserNames [ ] =
76
+ defaultCoachingRelationshipsWithUserNames ( ) ;
63
77
var err : string = "" ;
64
78
65
79
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
+ )
73
90
. then ( function ( response : AxiosResponse ) {
74
91
// handle success
75
92
console . debug ( response ) ;
76
93
if ( isCoachingRelationshipWithUserNamesArray ( response . data . data ) ) {
77
94
relationships = response . data . data ;
78
95
console . debug (
79
- `CoachingRelationshipsWithUserNames: ` + coachingRelationshipsWithUserNamesToString ( relationships ) + `.`
96
+ `CoachingRelationshipsWithUserNames: ` +
97
+ coachingRelationshipsWithUserNamesToString ( relationships ) +
98
+ `.`
80
99
) ;
81
100
}
82
101
} )
83
102
. catch ( function ( error : AxiosError ) {
84
103
// handle error
85
104
console . error ( error . response ?. status ) ;
86
105
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." ;
89
111
} else {
90
112
console . log ( error ) ;
91
113
console . error (
92
- `Retrieval of CoachingRelationshipsWithUserNames by organization Id (` + organizationId + `) failed.`
114
+ `Retrieval of CoachingRelationshipsWithUserNames by organization Id (` +
115
+ organizationId +
116
+ `) failed.`
93
117
) ;
94
118
err =
95
- `Retrieval of CoachingRealtionshipsWithUserNames by organization Id (` + organizationId + `) failed.` ;
119
+ `Retrieval of CoachingRealtionshipsWithUserNames by organization Id (` +
120
+ organizationId +
121
+ `) failed.` ;
96
122
}
97
123
} ) ;
98
124
0 commit comments