@@ -7,11 +7,11 @@ import {
7
7
GENERIC_PROJECT_MILESTONE_PRODUCT_NAME ,
8
8
GENERIC_PROJECT_MILESTONE_PRODUCT_TYPE ,
9
9
PHASE_PRODUCT_CHALLENGE_ID_FIELD ,
10
- PHASE_PRODUCT_TEMPLATE_ID
10
+ PHASE_PRODUCT_TEMPLATE_ID ,
11
+ PROJECTS_API_URL
11
12
} from '../config/constants'
12
13
import { paginationHeaders } from '../util/pagination'
13
-
14
- const { PROJECT_API_URL } = process . env
14
+ import { createProjectMemberInvite } from './projectMemberInvites'
15
15
16
16
/**
17
17
* Get billing accounts based on project id
@@ -21,7 +21,7 @@ const { PROJECT_API_URL } = process.env
21
21
* @returns {Promise<Object> } Billing accounts data
22
22
*/
23
23
export async function fetchBillingAccounts ( projectId ) {
24
- const response = await axiosInstance . get ( `${ PROJECT_API_URL } /${ projectId } /billingAccounts` )
24
+ const response = await axiosInstance . get ( `${ PROJECTS_API_URL } /${ projectId } /billingAccounts` )
25
25
return _ . get ( response , 'data' )
26
26
}
27
27
@@ -33,7 +33,7 @@ export async function fetchBillingAccounts (projectId) {
33
33
* @returns {Promise<Object> } Billing account data
34
34
*/
35
35
export async function fetchBillingAccount ( projectId ) {
36
- const response = await axiosInstance . get ( `${ PROJECT_API_URL } /${ projectId } /billingAccount` )
36
+ const response = await axiosInstance . get ( `${ PROJECTS_API_URL } /${ projectId } /billingAccount` )
37
37
return _ . get ( response , 'data' )
38
38
}
39
39
@@ -53,7 +53,7 @@ export function fetchMemberProjects (filters) {
53
53
}
54
54
}
55
55
56
- return axiosInstance . get ( `${ PROJECT_API_URL } ?${ queryString . stringify ( params ) } ` ) . then ( response => {
56
+ return axiosInstance . get ( `${ PROJECTS_API_URL } ?${ queryString . stringify ( params ) } ` ) . then ( response => {
57
57
return { projects : _ . get ( response , 'data' ) , pagination : paginationHeaders ( response ) }
58
58
} )
59
59
}
@@ -64,7 +64,7 @@ export function fetchMemberProjects (filters) {
64
64
* @returns {Promise<*> }
65
65
*/
66
66
export async function fetchProjectById ( id ) {
67
- const response = await axiosInstance . get ( `${ PROJECT_API_URL } /${ id } ` )
67
+ const response = await axiosInstance . get ( `${ PROJECTS_API_URL } /${ id } ` )
68
68
return _ . get ( response , 'data' )
69
69
}
70
70
@@ -74,7 +74,7 @@ export async function fetchProjectById (id) {
74
74
* @returns {Promise<*> }
75
75
*/
76
76
export async function fetchProjectPhases ( id ) {
77
- const response = await axiosInstance . get ( `${ PROJECT_API_URL } /${ id } /phases` , {
77
+ const response = await axiosInstance . get ( `${ PROJECTS_API_URL } /${ id } /phases` , {
78
78
params : {
79
79
fields : 'id,name,products,status'
80
80
}
@@ -90,7 +90,7 @@ export async function fetchProjectPhases (id) {
90
90
* @returns {Promise<*> }
91
91
*/
92
92
export async function updateProjectMemberRole ( projectId , memberRecordId , newRole ) {
93
- const response = await axiosInstance . patch ( `${ PROJECT_API_URL } /${ projectId } /members/${ memberRecordId } ` , {
93
+ const response = await axiosInstance . patch ( `${ PROJECTS_API_URL } /${ projectId } /members/${ memberRecordId } ` , {
94
94
role : newRole
95
95
} )
96
96
return _ . get ( response , 'data' )
@@ -104,21 +104,35 @@ export async function updateProjectMemberRole (projectId, memberRecordId, newRol
104
104
* @returns {Promise<*> }
105
105
*/
106
106
export async function addUserToProject ( projectId , userId , role ) {
107
- const response = await axiosInstance . post ( `${ PROJECT_API_URL } /${ projectId } /members` , {
107
+ const response = await axiosInstance . post ( `${ PROJECTS_API_URL } /${ projectId } /members` , {
108
108
userId,
109
109
role
110
110
} )
111
111
return _ . get ( response , 'data' )
112
112
}
113
113
114
+ /**
115
+ * adds the given user to the given project with the specified role
116
+ * @param projectId project id
117
+ * @param userId user id
118
+ * @param role
119
+ * @returns {Promise<*> }
120
+ */
121
+ export async function inviteUserToProject ( projectId , email , role ) {
122
+ return createProjectMemberInvite ( projectId , {
123
+ emails : [ email ] ,
124
+ role : role
125
+ } )
126
+ }
127
+
114
128
/**
115
129
* removes the given member record from the project
116
130
* @param projectId project id
117
131
* @param memberRecordId member record id
118
132
* @returns {Promise<*> }
119
133
*/
120
134
export async function removeUserFromProject ( projectId , memberRecordId ) {
121
- const response = await axiosInstance . delete ( `${ PROJECT_API_URL } /${ projectId } /members/${ memberRecordId } ` )
135
+ const response = await axiosInstance . delete ( `${ PROJECTS_API_URL } /${ projectId } /members/${ memberRecordId } ` )
122
136
return response
123
137
}
124
138
@@ -145,7 +159,7 @@ export async function saveChallengeAsPhaseProduct (projectId, phaseId, challenge
145
159
estimatedPrice : 1
146
160
}
147
161
148
- return axiosInstance . post ( `${ PROJECT_API_URL } /${ projectId } /phases/${ phaseId } /products` ,
162
+ return axiosInstance . post ( `${ PROJECTS_API_URL } /${ projectId } /phases/${ phaseId } /products` ,
149
163
_ . set ( payload , PHASE_PRODUCT_CHALLENGE_ID_FIELD , challengeId )
150
164
)
151
165
}
@@ -176,7 +190,7 @@ export async function removeChallengeFromPhaseProduct (projectId, challengeId) {
176
190
177
191
if ( selectedMilestoneProduct ) {
178
192
// If its the only challenge in product and product doesn't contain any other detail just delete it
179
- return axiosInstance . delete ( `${ PROJECT_API_URL } /${ projectId } /phases/${ selectedMilestoneProduct . phaseId } /products/${ selectedMilestoneProduct . productId } ` )
193
+ return axiosInstance . delete ( `${ PROJECTS_API_URL } /${ projectId } /phases/${ selectedMilestoneProduct . phaseId } /products/${ selectedMilestoneProduct . productId } ` )
180
194
}
181
195
}
182
196
@@ -186,7 +200,7 @@ export async function removeChallengeFromPhaseProduct (projectId, challengeId) {
186
200
* @returns {Promise<*> }
187
201
*/
188
202
export async function createProjectApi ( project ) {
189
- const response = await axiosInstance . post ( `${ PROJECT_API_URL } ` , project )
203
+ const response = await axiosInstance . post ( `${ PROJECTS_API_URL } ` , project )
190
204
return _ . get ( response , 'data' )
191
205
}
192
206
@@ -197,7 +211,7 @@ export async function createProjectApi (project) {
197
211
* @returns {Promise<*> }
198
212
*/
199
213
export async function updateProjectApi ( projectId , project ) {
200
- const response = await axiosInstance . patch ( `${ PROJECT_API_URL } /${ projectId } ` , project )
214
+ const response = await axiosInstance . patch ( `${ PROJECTS_API_URL } /${ projectId } ` , project )
201
215
return _ . get ( response , 'data' )
202
216
}
203
217
@@ -206,7 +220,7 @@ export async function updateProjectApi (projectId, project) {
206
220
* @returns {Promise<*> }
207
221
*/
208
222
export async function getProjectTypes ( ) {
209
- const response = await axiosInstance . get ( `${ PROJECT_API_URL } /metadata/projectTypes` )
223
+ const response = await axiosInstance . get ( `${ PROJECTS_API_URL } /metadata/projectTypes` )
210
224
return _ . get ( response , 'data' )
211
225
}
212
226
@@ -218,7 +232,7 @@ export async function getProjectTypes () {
218
232
*/
219
233
export async function getProjectAttachment ( projectId , attachmentId ) {
220
234
const response = await axiosInstance . get (
221
- `${ PROJECT_API_URL } /${ projectId } /attachments/${ attachmentId } `
235
+ `${ PROJECTS_API_URL } /${ projectId } /attachments/${ attachmentId } `
222
236
)
223
237
return _ . get ( response , 'data' )
224
238
}
@@ -241,7 +255,7 @@ export async function addProjectAttachmentApi (projectId, data) {
241
255
}
242
256
243
257
const response = await axiosInstance . post (
244
- `${ PROJECT_API_URL } /${ projectId } /attachments` ,
258
+ `${ PROJECTS_API_URL } /${ projectId } /attachments` ,
245
259
data
246
260
)
247
261
return _ . get ( response , 'data' )
@@ -272,7 +286,7 @@ export async function updateProjectAttachmentApi (
272
286
}
273
287
274
288
const response = await axiosInstance . patch (
275
- `${ PROJECT_API_URL } /${ projectId } /attachments/${ attachmentId } ` ,
289
+ `${ PROJECTS_API_URL } /${ projectId } /attachments/${ attachmentId } ` ,
276
290
data
277
291
)
278
292
return _ . get ( response , 'data' )
@@ -285,6 +299,6 @@ export async function updateProjectAttachmentApi (
285
299
*/
286
300
export async function removeProjectAttachmentApi ( projectId , attachmentId ) {
287
301
await axiosInstance . delete (
288
- `${ PROJECT_API_URL } /${ projectId } /attachments/${ attachmentId } `
302
+ `${ PROJECTS_API_URL } /${ projectId } /attachments/${ attachmentId } `
289
303
)
290
304
}
0 commit comments