Skip to content

Commit 2d0f5cc

Browse files
committed
Added most needed events.
1 parent 6084631 commit 2d0f5cc

File tree

2 files changed

+35
-1
lines changed

2 files changed

+35
-1
lines changed

src/constants.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,12 @@ export const BUS_API_EVENT = {
6161
PROJECT_CANCELED: 'notifications.connect.project.canceled',
6262
PROJECT_ACTIVE: 'notifications.connect.project.active',
6363

64+
PROJECT_PHASE_TRANSITION_ACTIVE: 'project.phase.transition.active',
65+
PROJECT_PHASE_TRANSITION_COMPLETED: 'project.phase.transition.completed',
66+
PROJECT_PHASE_UPDATE_PAYMENT: 'project.phase.update.payment',
67+
PROJECT_PHASE_UPDATE_PROGRESS: 'project.phase.update.progress',
68+
PROJECT_PHASE_UPDATE_SCOPE: 'project.phase.update.scope',
69+
6470
MEMBER_JOINED: 'notifications.connect.project.member.joined',
6571
MEMBER_LEFT: 'notifications.connect.project.member.left',
6672
MEMBER_REMOVED: 'notifications.connect.project.member.removed',
@@ -71,12 +77,16 @@ export const BUS_API_EVENT = {
7177
PROJECT_LINK_CREATED: 'notifications.connect.project.linkCreated',
7278
PROJECT_FILE_UPLOADED: 'notifications.connect.project.fileUploaded',
7379
PROJECT_SPECIFICATION_MODIFIED: 'notifications.connect.project.specificationModified',
80+
PROJECT_PROGRESS_MODIFIED: 'notifications.connect.project.progressModified',
7481

7582
// When phase is added/updated/deleted from the project,
7683
// When product is added/deleted from a phase
7784
// When product is updated on any field other than specification
7885
PROJECT_PLAN_MODIFIED: 'notifications.connect.project.planModified',
7986

87+
// TODO: add logic to send this event
88+
PROJECT_PLAN_READY: 'notifications.connect.project.planReady',
89+
8090
// When specification of a product is modified
8191
PROJECT_PRODUCT_SPECIFICATION_MODIFIED: 'notifications.connect.project.productSpecificationModified',
8292
};

src/events/busApi.js

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import _ from 'lodash';
22
import 'config';
3-
import { EVENT, BUS_API_EVENT, PROJECT_STATUS, PROJECT_MEMBER_ROLE } from '../constants';
3+
import { EVENT, BUS_API_EVENT, PROJECT_STATUS, PROJECT_PHASE_STATUS, PROJECT_MEMBER_ROLE } from '../constants';
44
import { createEvent } from '../services/busApi';
55
import models from '../models';
66

@@ -226,6 +226,7 @@ module.exports = (app, logger) => {
226226
logger.debug('receive PROJECT_PHASE_UPDATED event');
227227

228228
const projectId = _.parseInt(req.params.projectId);
229+
const phaseId = _.parseInt(req.params.phaseId);
229230

230231
models.Project.findOne({
231232
where: { id: projectId },
@@ -237,6 +238,29 @@ module.exports = (app, logger) => {
237238
userId: req.authUser.userId,
238239
initiatorUserId: req.authUser.userId,
239240
}, logger);
241+
242+
[
243+
['spentBudget', BUS_API_EVENT.PROJECT_PHASE_UPDATE_PAYMENT],
244+
['progress', [BUS_API_EVENT.PROJECT_PHASE_UPDATE_PROGRESS, BUS_API_EVENT.PROJECT_PROGRESS_MODIFIED]],
245+
['details', BUS_API_EVENT.PROJECT_PHASE_UPDATE_SCOPE],
246+
['status', BUS_API_EVENT.PROJECT_PHASE_TRANSITION_ACTIVE, PROJECT_PHASE_STATUS.ACTIVE],
247+
['status', BUS_API_EVENT.PROJECT_PHASE_TRANSITION_COMPLETED, PROJECT_PHASE_STATUS.COMPLETED],
248+
].forEach(([key, events, sendIfEqual]) => {
249+
// eslint-disable-next-line no-param-reassign
250+
events = Array.isArray(events) ? events : [events];
251+
252+
// send event(s) only if the target field's value was updated, or when an update matches a "sendIfEqual" value
253+
if ((!sendIfEqual && !_.isEqual(original[key], updated[key])) ||
254+
(original[key] !== sendIfEqual && updated[key] === sendIfEqual)) {
255+
events.forEach(event => createEvent(event, {
256+
projectId,
257+
phaseId,
258+
projectName: project.name,
259+
userId: req.authUser.userId,
260+
initiatorUserId: req.authUser.userId,
261+
}, logger));
262+
}
263+
});
240264
}).catch(err => null); // eslint-disable-line no-unused-vars
241265
});
242266

0 commit comments

Comments
 (0)