@@ -2,34 +2,22 @@ import _ from 'lodash'
2
2
import qs from 'qs'
3
3
import { axiosInstance } from './axiosWithAuth'
4
4
import FormData from 'form-data'
5
- import { MEMBER_API_URL , CHALLENGE_API_URL , PROJECT_API_URL , API_V3_URL , API_V4_URL } from '../config/constants'
6
-
7
- /**
8
- * Api request for fetching member's active challenges
9
- * @returns {Promise<*> }
10
- */
11
- export async function fetchMemberChallenges ( handle ) {
12
- const response = await axiosInstance . get ( `${ MEMBER_API_URL } /${ handle } /challenges?filter=status=ACTIVE` )
13
- return _ . get ( response , 'data.result.content' )
14
- }
15
-
16
- /**
17
- * Api request for fetching member's challenge (it includes member roles)
18
- * @param {String } handle
19
- * @param challengeId
20
- * @returns {Promise<*> }
21
- */
22
- export async function fetchMemberChallenge ( handle , challengeId ) {
23
- const response = await axiosInstance . get ( `${ CHALLENGE_API_URL } /members/${ handle } /challenges?filter=id=${ challengeId } ` )
24
- return _ . get ( response , 'data.result.content[0]' )
25
- }
5
+ const {
6
+ CHALLENGE_API_URL ,
7
+ CHALLENGE_TYPES_URL ,
8
+ CHALLENGE_TIMELINE_TEMPLATES_URL ,
9
+ CHALLENGE_PHASES_URL ,
10
+ GROUPS_API_URL ,
11
+ PLATFORMS_V4_API_URL ,
12
+ TECHNOLOGIES_V4_API_URL
13
+ } = process . env
26
14
27
15
/**
28
16
* Api request for fetching challenge types
29
17
* @returns {Promise<*> }
30
18
*/
31
19
export async function fetchChallengeTypes ( ) {
32
- const response = await axiosInstance . get ( `${ CHALLENGE_API_URL } /challengetypes ?isActive=true` )
20
+ const response = await axiosInstance . get ( `${ CHALLENGE_TYPES_URL } ?isActive=true` )
33
21
return _ . get ( response , 'data' , [ ] )
34
22
}
35
23
@@ -38,8 +26,8 @@ export async function fetchChallengeTypes () {
38
26
* @returns {Promise<*> }
39
27
*/
40
28
export async function fetchChallengeTags ( ) {
41
- const platforms = await axiosInstance . get ( ` ${ API_V4_URL } /platforms` )
42
- const technologies = await axiosInstance . get ( ` ${ API_V4_URL } /technologies` )
29
+ const platforms = await axiosInstance . get ( PLATFORMS_V4_API_URL )
30
+ const technologies = await axiosInstance . get ( TECHNOLOGIES_V4_API_URL )
43
31
return [
44
32
..._ . map ( _ . get ( platforms , 'data.result.content' , [ ] ) , tag => _ . pick ( tag , 'name' ) ) ,
45
33
..._ . map ( _ . get ( technologies , 'data.result.content' , [ ] ) , tag => _ . pick ( tag , 'name' ) )
@@ -51,7 +39,7 @@ export async function fetchChallengeTags () {
51
39
* @returns {Promise<*> }
52
40
*/
53
41
export async function fetchGroups ( ) {
54
- const response = await axiosInstance . get ( ` ${ API_V3_URL } /groups` )
42
+ const response = await axiosInstance . get ( GROUPS_API_URL )
55
43
return _ . get ( response , 'data.result.content' , [ ] )
56
44
}
57
45
@@ -60,7 +48,7 @@ export async function fetchGroups () {
60
48
* @returns {Promise<*> }
61
49
*/
62
50
export async function fetchTimelineTemplates ( ) {
63
- const response = await axiosInstance . get ( ` ${ CHALLENGE_API_URL } /timelinetemplates` )
51
+ const response = await axiosInstance . get ( CHALLENGE_TIMELINE_TEMPLATES_URL )
64
52
return _ . get ( response , 'data' , [ ] )
65
53
}
66
54
@@ -69,7 +57,7 @@ export async function fetchTimelineTemplates () {
69
57
* @returns {Promise<*> }
70
58
*/
71
59
export async function fetchChallengePhases ( ) {
72
- const response = await axiosInstance . get ( ` ${ CHALLENGE_API_URL } /challengephases` )
60
+ const response = await axiosInstance . get ( CHALLENGE_PHASES_URL )
73
61
return _ . get ( response , 'data' , [ ] )
74
62
}
75
63
@@ -79,37 +67,17 @@ export async function fetchChallengePhases () {
79
67
* @returns {Promise<*> }
80
68
*/
81
69
export async function fetchChallenge ( challengeId ) {
82
- const response = await axiosInstance . get ( `${ CHALLENGE_API_URL } /challenges/ ${ challengeId } ` )
70
+ const response = await axiosInstance . get ( `${ CHALLENGE_API_URL } /${ challengeId } ` )
83
71
return _ . get ( response , 'data' )
84
72
}
85
73
86
- /**
87
- * Api request for fetching project's challenges
88
- * @param projectId Project id
89
- * @param status Challenge status
90
- * @returns {Promise<*> }
91
- */
92
- export async function fetchProjectChallenges ( projectId , status ) {
93
- let filters = [ ]
94
- if ( _ . isEmpty ( projectId ) ) {
95
- status = 'ACTIVE'
96
- } else {
97
- filters . push ( `projectId=${ projectId } ` )
98
- }
99
- if ( ! _ . isEmpty ( status ) ) {
100
- filters . push ( `status=${ status } ` )
101
- }
102
- const response = await axiosInstance . get ( `${ PROJECT_API_URL } /challenges${ filters . length > 0 ? `?filter=${ encodeURIComponent ( filters . join ( '&' ) ) } ` : '' } ` )
103
- return _ . get ( response , 'data.result.content' )
104
- }
105
-
106
74
/**
107
75
* Api request for creating new challenge
108
76
* @param challenge challenge data
109
77
* @returns {Promise<*> }
110
78
*/
111
79
export function createChallenge ( challenge ) {
112
- return axiosInstance . post ( ` ${ CHALLENGE_API_URL } /challenges` , challenge )
80
+ return axiosInstance . post ( CHALLENGE_API_URL , challenge )
113
81
}
114
82
115
83
/**
@@ -119,13 +87,13 @@ export function createChallenge (challenge) {
119
87
* @returns {Promise<*> }
120
88
*/
121
89
export function updateChallenge ( challenge , challengeId ) {
122
- return axiosInstance . put ( `${ CHALLENGE_API_URL } /challenges/ ${ challengeId } ` , challenge )
90
+ return axiosInstance . put ( `${ CHALLENGE_API_URL } /${ challengeId } ` , challenge )
123
91
}
124
92
125
93
export function uploadAttachment ( challengeId , file ) {
126
94
const data = new FormData ( )
127
95
data . append ( 'attachment' , file )
128
- return axiosInstance . post ( `${ CHALLENGE_API_URL } /challenges/ ${ challengeId } /attachments` , data )
96
+ return axiosInstance . post ( `${ CHALLENGE_API_URL } /${ challengeId } /attachments` , data )
129
97
}
130
98
131
99
/**
@@ -138,7 +106,8 @@ export function fetchChallenges (filters, params) {
138
106
...filters ,
139
107
...params
140
108
}
141
- return axiosInstance . get ( `${ CHALLENGE_API_URL } /challenges?${ qs . stringify ( query , { encode : false } ) } ` )
109
+ console . log ( { query } )
110
+ return axiosInstance . get ( `${ CHALLENGE_API_URL } ?${ qs . stringify ( query , { encode : false } ) } ` )
142
111
}
143
112
144
113
/**
@@ -147,5 +116,5 @@ export function fetchChallenges (filters, params) {
147
116
* @param params
148
117
*/
149
118
export function patchChallenge ( challengeId , params ) {
150
- return axiosInstance . patch ( `${ CHALLENGE_API_URL } /challenges/ ${ challengeId } ` , params )
119
+ return axiosInstance . patch ( `${ CHALLENGE_API_URL } /${ challengeId } ` , params )
151
120
}
0 commit comments