Skip to content

turn a job into in-review status after it has a candidate #98

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 51 additions & 0 deletions src/eventHandlers/JobCandidateEventHandler.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/*
* Handle events for JobCandidate.
*/

const models = require('../models')
const logger = require('../common/logger')
const helper = require('../common/helper')
const JobService = require('../services/JobService')

/**
* Once we create at least one JobCandidate for a Job, the Job status should be changed to in-review.
*
* @param {Object} payload the event payload
* @returns {undefined}
*/
async function inReviewJob (payload) {
const job = await models.Job.findById(payload.value.jobId)
if (job.status === 'in-review') {
logger.debug({
component: 'JobCandidateEventHandler',
context: 'inReviewJob',
message: `id: ${job.id} job is already in in-review status`
})
return
}
await JobService.partiallyUpdateJob(
helper.getAuditM2Muser(),
job.id,
{ status: 'in-review' }
).then(result => {
logger.info({
component: 'JobCandidateEventHandler',
context: 'inReviewJob',
message: `id: ${result.id} job got in-review status.`
})
})
}

/**
* Process job candidate create event.
*
* @param {Object} payload the event payload
* @returns {undefined}
*/
async function processCreate (payload) {
await inReviewJob(payload)
}

module.exports = {
processCreate
}
2 changes: 2 additions & 0 deletions src/eventHandlers/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,13 @@
const config = require('config')
const eventDispatcher = require('../common/eventDispatcher')
const JobEventHandler = require('./JobEventHandler')
const JobCandidateEventHandler = require('./JobCandidateEventHandler')
const ResourceBookingEventHandler = require('./ResourceBookingEventHandler')
const logger = require('../common/logger')

const TopicOperationMapping = {
[config.TAAS_JOB_UPDATE_TOPIC]: JobEventHandler.processUpdate,
[config.TAAS_JOB_CANDIDATE_CREATE_TOPIC]: JobCandidateEventHandler.processCreate,
[config.TAAS_RESOURCE_BOOKING_UPDATE_TOPIC]: ResourceBookingEventHandler.processUpdate
}

Expand Down