Skip to content

Commit c1225a2

Browse files
authored
Merge pull request #98 from imcaizheng/auto-change-job-status-in-review
turn a job into in-review status after it has a candidate
2 parents 205f264 + 563aa7a commit c1225a2

File tree

2 files changed

+53
-0
lines changed

2 files changed

+53
-0
lines changed
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
/*
2+
* Handle events for JobCandidate.
3+
*/
4+
5+
const models = require('../models')
6+
const logger = require('../common/logger')
7+
const helper = require('../common/helper')
8+
const JobService = require('../services/JobService')
9+
10+
/**
11+
* Once we create at least one JobCandidate for a Job, the Job status should be changed to in-review.
12+
*
13+
* @param {Object} payload the event payload
14+
* @returns {undefined}
15+
*/
16+
async function inReviewJob (payload) {
17+
const job = await models.Job.findById(payload.value.jobId)
18+
if (job.status === 'in-review') {
19+
logger.debug({
20+
component: 'JobCandidateEventHandler',
21+
context: 'inReviewJob',
22+
message: `id: ${job.id} job is already in in-review status`
23+
})
24+
return
25+
}
26+
await JobService.partiallyUpdateJob(
27+
helper.getAuditM2Muser(),
28+
job.id,
29+
{ status: 'in-review' }
30+
).then(result => {
31+
logger.info({
32+
component: 'JobCandidateEventHandler',
33+
context: 'inReviewJob',
34+
message: `id: ${result.id} job got in-review status.`
35+
})
36+
})
37+
}
38+
39+
/**
40+
* Process job candidate create event.
41+
*
42+
* @param {Object} payload the event payload
43+
* @returns {undefined}
44+
*/
45+
async function processCreate (payload) {
46+
await inReviewJob(payload)
47+
}
48+
49+
module.exports = {
50+
processCreate
51+
}

src/eventHandlers/index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,13 @@
55
const config = require('config')
66
const eventDispatcher = require('../common/eventDispatcher')
77
const JobEventHandler = require('./JobEventHandler')
8+
const JobCandidateEventHandler = require('./JobCandidateEventHandler')
89
const ResourceBookingEventHandler = require('./ResourceBookingEventHandler')
910
const logger = require('../common/logger')
1011

1112
const TopicOperationMapping = {
1213
[config.TAAS_JOB_UPDATE_TOPIC]: JobEventHandler.processUpdate,
14+
[config.TAAS_JOB_CANDIDATE_CREATE_TOPIC]: JobCandidateEventHandler.processCreate,
1315
[config.TAAS_RESOURCE_BOOKING_UPDATE_TOPIC]: ResourceBookingEventHandler.processUpdate
1416
}
1517

0 commit comments

Comments
 (0)