|
| 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 | +} |
0 commit comments