Skip to content
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
15 changes: 15 additions & 0 deletions docs/swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1734,6 +1734,11 @@ components:
example: "Dummy title"
description: "The title."
maxLength: 64
status:
type: string
enum: ['sourcing', 'in-review', 'assigned', 'closed', 'cancelled']
description: "The job status."
default: sourcing
startDate:
type: string
format: date-time
Expand Down Expand Up @@ -1829,6 +1834,11 @@ components:
format: uuid
example: "a55fe1bc-1754-45fa-9adc-cf3d6d7c377a"
description: "The user id."
status:
type: string
enum: ['open', 'selected', 'shortlist', 'rejected', 'cancelled']
description: "The job candidate status."
default: open
externalId:
type: string
example: "1212"
Expand Down Expand Up @@ -1983,6 +1993,11 @@ components:
type: string
format: uuid
description: "The job id."
status:
type: string
enum: ['sourcing', 'in-review', 'assigned', 'closed', 'cancelled']
description: "The job status."
default: sourcing
startDate:
type: string
format: date-time
Expand Down
17 changes: 15 additions & 2 deletions src/eventHandlers/ResourceBookingEventHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
*/

const { Op } = require('sequelize')
const _ = require('lodash')
const models = require('../models')
const logger = require('../common/logger')
const helper = require('../common/helper')
Expand All @@ -18,7 +19,7 @@ const JobCandidateService = require('../services/JobCandidateService')
* @returns {undefined}
*/
async function selectJobCandidate (payload) {
if (payload.value.status === payload.options.oldValue.status) {
if (_.get(payload, 'options.oldValue') && payload.value.status === payload.options.oldValue.status) {
logger.debug({
component: 'ResourceBookingEventHandler',
context: 'selectJobCandidate',
Expand Down Expand Up @@ -73,7 +74,7 @@ async function selectJobCandidate (payload) {
* @returns {undefined}
*/
async function assignJob (payload) {
if (payload.value.status === payload.options.oldValue.status) {
if (_.get(payload, 'options.oldValue') && payload.value.status === payload.options.oldValue.status) {
logger.debug({
component: 'ResourceBookingEventHandler',
context: 'assignJob',
Expand Down Expand Up @@ -125,6 +126,17 @@ async function assignJob (payload) {
}
}

/**
* Process resource booking create event.
*
* @param {Object} payload the event payload
* @returns {undefined}
*/
async function processCreate (payload) {
await selectJobCandidate(payload)
await assignJob(payload)
}

/**
* Process resource booking update event.
*
Expand All @@ -137,5 +149,6 @@ async function processUpdate (payload) {
}

module.exports = {
processCreate,
processUpdate
}
1 change: 1 addition & 0 deletions src/eventHandlers/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ 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_CREATE_TOPIC]: ResourceBookingEventHandler.processCreate,
[config.TAAS_RESOURCE_BOOKING_UPDATE_TOPIC]: ResourceBookingEventHandler.processUpdate
}

Expand Down
2 changes: 1 addition & 1 deletion src/services/JobCandidateService.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,6 @@ async function createJobCandidate (currentUser, jobCandidate) {
jobCandidate.id = uuid()
jobCandidate.createdAt = new Date()
jobCandidate.createdBy = await helper.getUserId(currentUser.userId)
jobCandidate.status = 'open'

const created = await JobCandidate.create(jobCandidate)
await helper.postEvent(config.TAAS_JOB_CANDIDATE_CREATE_TOPIC, jobCandidate)
Expand All @@ -102,6 +101,7 @@ async function createJobCandidate (currentUser, jobCandidate) {
createJobCandidate.schema = Joi.object().keys({
currentUser: Joi.object().required(),
jobCandidate: Joi.object().keys({
status: Joi.jobCandidateStatus().default('open'),
jobId: Joi.string().uuid().required(),
userId: Joi.string().uuid().required(),
externalId: Joi.string(),
Expand Down
2 changes: 1 addition & 1 deletion src/services/JobService.js
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,6 @@ async function createJob (currentUser, job) {
job.id = uuid()
job.createdAt = new Date()
job.createdBy = await helper.getUserId(currentUser.userId)
job.status = 'sourcing'

const created = await Job.create(job)
await helper.postEvent(config.TAAS_JOB_CREATE_TOPIC, job)
Expand All @@ -162,6 +161,7 @@ async function createJob (currentUser, job) {
createJob.schema = Joi.object().keys({
currentUser: Joi.object().required(),
job: Joi.object().keys({
status: Joi.jobStatus().default('sourcing'),
projectId: Joi.number().integer().required(),
externalId: Joi.string(),
description: Joi.string(),
Expand Down
2 changes: 1 addition & 1 deletion src/services/ResourceBookingService.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,6 @@ async function createResourceBooking (currentUser, resourceBooking) {
resourceBooking.id = uuid()
resourceBooking.createdAt = new Date()
resourceBooking.createdBy = await helper.getUserId(currentUser.userId)
resourceBooking.status = 'sourcing'

const created = await ResourceBooking.create(resourceBooking)
await helper.postEvent(config.TAAS_RESOURCE_BOOKING_CREATE_TOPIC, resourceBooking)
Expand All @@ -115,6 +114,7 @@ async function createResourceBooking (currentUser, resourceBooking) {
createResourceBooking.schema = Joi.object().keys({
currentUser: Joi.object().required(),
resourceBooking: Joi.object().keys({
status: Joi.jobStatus().default('sourcing'),
projectId: Joi.number().integer().required(),
userId: Joi.string().uuid().required(),
jobId: Joi.string().uuid(),
Expand Down