Skip to content

Commit b22c005

Browse files
committed
Added logic for the plan ready event.
1 parent 2d0f5cc commit b22c005

File tree

2 files changed

+32
-1
lines changed

2 files changed

+32
-1
lines changed

src/constants.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,6 @@ export const BUS_API_EVENT = {
8484
// When product is updated on any field other than specification
8585
PROJECT_PLAN_MODIFIED: 'notifications.connect.project.planModified',
8686

87-
// TODO: add logic to send this event
8887
PROJECT_PLAN_READY: 'notifications.connect.project.planReady',
8988

9089
// When specification of a product is modified

src/events/busApi.js

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,34 @@ module.exports = (app, logger) => {
177177
}).catch(err => null); // eslint-disable-line no-unused-vars
178178
});
179179

180+
/**
181+
* If the project is in draft status and the phase is in reviewed status, and it's the
182+
* only phase in the project with that status, then send the plan ready event.
183+
*
184+
* @param req
185+
* @param project
186+
* @param phase
187+
* @returns {Promise<void>}
188+
*/
189+
async function sendPlanReadyEventIfNeeded(req, project, phase) {
190+
if (project.status === PROJECT_STATUS.DRAFT &&
191+
phase.status === PROJECT_PHASE_STATUS.REVIEWED) {
192+
models.ProjectPhase.count({
193+
where: { projectId: project.id, status: PROJECT_PHASE_STATUS.REVIEWED }
194+
}).then((count => {
195+
// only send the plan ready event when this is the only reviewed phase in the project
196+
if (count !== 1) { return; }
197+
createEvent(BUS_API_EVENT.PROJECT_PLAN_READY, {
198+
projectId: project.id,
199+
phaseId: phase.id,
200+
projectName: project.name,
201+
userId: req.authUser.userId,
202+
initiatorUserId: req.authUser.userId,
203+
}, logger)
204+
}));
205+
}
206+
}
207+
180208
/**
181209
* PROJECT_PHASE_ADDED
182210
*/
@@ -195,6 +223,8 @@ module.exports = (app, logger) => {
195223
userId: req.authUser.userId,
196224
initiatorUserId: req.authUser.userId,
197225
}, logger);
226+
227+
return sendPlanReadyEventIfNeeded(req, project, created);
198228
}).catch(err => null); // eslint-disable-line no-unused-vars
199229
});
200230

@@ -261,6 +291,8 @@ module.exports = (app, logger) => {
261291
}, logger));
262292
}
263293
});
294+
295+
return sendPlanReadyEventIfNeeded(req, project, updated);
264296
}).catch(err => null); // eslint-disable-line no-unused-vars
265297
});
266298

0 commit comments

Comments
 (0)