1
1
import _ from 'lodash' ;
2
- import 'config' ;
2
+ import config from 'config' ;
3
3
import { EVENT , BUS_API_EVENT , PROJECT_STATUS , PROJECT_MEMBER_ROLE } from '../constants' ;
4
4
import { createEvent } from '../services/busApi' ;
5
5
import models from '../models' ;
@@ -17,6 +17,27 @@ const mapEventTypes = {
17
17
[ PROJECT_STATUS . ACTIVE ] : BUS_API_EVENT . PROJECT_ACTIVE ,
18
18
} ;
19
19
20
+ /**
21
+ * Builds the connect project attachment url for the given project and attachment ids.
22
+ *
23
+ * @param {string|number } projectId the project id
24
+ * @param {string|number } attachmentId the attachment id
25
+ * @returns {string } the connect project attachment url
26
+ */
27
+ function connectProjectAttachmentUrl ( projectId , attachmentId ) {
28
+ return `${ config . get ( 'connectProjectsUrl' ) } ${ projectId } /attachments/${ attachmentId } ` ;
29
+ }
30
+
31
+ /**
32
+ * Builds the connect project url for the given project id.
33
+ *
34
+ * @param {string|number } projectId the project id
35
+ * @returns {string } the connect project url
36
+ */
37
+ function connectProjectUrl ( projectId ) {
38
+ return `${ config . get ( 'connectProjectsUrl' ) } ${ projectId } ` ;
39
+ }
40
+
20
41
module . exports = ( app , logger ) => {
21
42
/**
22
43
* PROJECT_DRAFT_CREATED
@@ -28,6 +49,7 @@ module.exports = (app, logger) => {
28
49
createEvent ( BUS_API_EVENT . PROJECT_CREATED , {
29
50
projectId : project . id ,
30
51
projectName : project . name ,
52
+ projectUrl : connectProjectUrl ( project . id ) ,
31
53
userId : req . authUser . userId ,
32
54
initiatorUserId : req . authUser . userId ,
33
55
} , logger ) ;
@@ -44,6 +66,7 @@ module.exports = (app, logger) => {
44
66
createEvent ( mapEventTypes [ updated . status ] , {
45
67
projectId : updated . id ,
46
68
projectName : updated . name ,
69
+ projectUrl : connectProjectUrl ( updated . id ) ,
47
70
userId : req . authUser . userId ,
48
71
initiatorUserId : req . authUser . userId ,
49
72
} , logger ) ;
@@ -55,6 +78,7 @@ module.exports = (app, logger) => {
55
78
createEvent ( BUS_API_EVENT . PROJECT_SPECIFICATION_MODIFIED , {
56
79
projectId : updated . id ,
57
80
projectName : updated . name ,
81
+ projectUrl : connectProjectUrl ( updated . id ) ,
58
82
userId : req . authUser . userId ,
59
83
initiatorUserId : req . authUser . userId ,
60
84
} , logger ) ;
@@ -63,6 +87,7 @@ module.exports = (app, logger) => {
63
87
createEvent ( BUS_API_EVENT . PROJECT_LINK_CREATED , {
64
88
projectId : updated . id ,
65
89
projectName : updated . name ,
90
+ projectUrl : connectProjectUrl ( updated . id ) ,
66
91
userId : req . authUser . userId ,
67
92
initiatorUserId : req . authUser . userId ,
68
93
} , logger ) ;
@@ -96,6 +121,7 @@ module.exports = (app, logger) => {
96
121
createEvent ( eventType , {
97
122
projectId,
98
123
projectName : project . name ,
124
+ projectUrl : connectProjectUrl ( projectId ) ,
99
125
userId : member . userId ,
100
126
initiatorUserId : req . authUser . userId ,
101
127
} , logger ) ;
@@ -124,6 +150,7 @@ module.exports = (app, logger) => {
124
150
createEvent ( eventType , {
125
151
projectId,
126
152
projectName : project . name ,
153
+ projectUrl : connectProjectUrl ( projectId ) ,
127
154
userId : member . userId ,
128
155
initiatorUserId : req . authUser . userId ,
129
156
} , logger ) ;
@@ -147,6 +174,7 @@ module.exports = (app, logger) => {
147
174
createEvent ( BUS_API_EVENT . MEMBER_ASSIGNED_AS_OWNER , {
148
175
projectId,
149
176
projectName : project . name ,
177
+ projectUrl : connectProjectUrl ( projectId ) ,
150
178
userId : updated . userId ,
151
179
initiatorUserId : req . authUser . userId ,
152
180
} , logger ) ;
@@ -170,7 +198,9 @@ module.exports = (app, logger) => {
170
198
createEvent ( BUS_API_EVENT . PROJECT_FILE_UPLOADED , {
171
199
projectId,
172
200
projectName : project . name ,
201
+ projectUrl : connectProjectUrl ( projectId ) ,
173
202
fileName : attachment . filePath . replace ( / ^ .* [ \\ \/ ] / , '' ) , // eslint-disable-line
203
+ fileUrl : connectProjectAttachmentUrl ( projectId , attachment . id ) ,
174
204
userId : req . authUser . userId ,
175
205
initiatorUserId : req . authUser . userId ,
176
206
} , logger ) ;
@@ -192,6 +222,7 @@ module.exports = (app, logger) => {
192
222
createEvent ( BUS_API_EVENT . PROJECT_PLAN_MODIFIED , {
193
223
projectId,
194
224
projectName : project . name ,
225
+ projectUrl : connectProjectUrl ( projectId ) ,
195
226
userId : req . authUser . userId ,
196
227
initiatorUserId : req . authUser . userId ,
197
228
} , logger ) ;
@@ -213,6 +244,7 @@ module.exports = (app, logger) => {
213
244
createEvent ( BUS_API_EVENT . PROJECT_PLAN_MODIFIED , {
214
245
projectId,
215
246
projectName : project . name ,
247
+ projectUrl : connectProjectUrl ( projectId ) ,
216
248
userId : req . authUser . userId ,
217
249
initiatorUserId : req . authUser . userId ,
218
250
} , logger ) ;
@@ -234,6 +266,7 @@ module.exports = (app, logger) => {
234
266
createEvent ( BUS_API_EVENT . PROJECT_PLAN_MODIFIED , {
235
267
projectId,
236
268
projectName : project . name ,
269
+ projectUrl : connectProjectUrl ( projectId ) ,
237
270
userId : req . authUser . userId ,
238
271
initiatorUserId : req . authUser . userId ,
239
272
} , logger ) ;
@@ -255,6 +288,7 @@ module.exports = (app, logger) => {
255
288
createEvent ( BUS_API_EVENT . PROJECT_PLAN_MODIFIED , {
256
289
projectId,
257
290
projectName : project . name ,
291
+ projectUrl : connectProjectUrl ( projectId ) ,
258
292
userId : req . authUser . userId ,
259
293
initiatorUserId : req . authUser . userId ,
260
294
phase : created ,
@@ -277,6 +311,7 @@ module.exports = (app, logger) => {
277
311
createEvent ( BUS_API_EVENT . PROJECT_PLAN_MODIFIED , {
278
312
projectId,
279
313
projectName : project . name ,
314
+ projectUrl : connectProjectUrl ( projectId ) ,
280
315
userId : req . authUser . userId ,
281
316
initiatorUserId : req . authUser . userId ,
282
317
} , logger ) ;
@@ -302,6 +337,7 @@ module.exports = (app, logger) => {
302
337
createEvent ( BUS_API_EVENT . PROJECT_PRODUCT_SPECIFICATION_MODIFIED , {
303
338
projectId,
304
339
projectName : project . name ,
340
+ projectUrl : connectProjectUrl ( projectId ) ,
305
341
userId : req . authUser . userId ,
306
342
initiatorUserId : req . authUser . userId ,
307
343
} , logger ) ;
@@ -314,6 +350,7 @@ module.exports = (app, logger) => {
314
350
createEvent ( BUS_API_EVENT . PROJECT_PLAN_MODIFIED , {
315
351
projectId,
316
352
projectName : project . name ,
353
+ projectUrl : connectProjectUrl ( projectId ) ,
317
354
userId : req . authUser . userId ,
318
355
initiatorUserId : req . authUser . userId ,
319
356
} , logger ) ;
0 commit comments