Skip to content

Commit cceef5d

Browse files
authored
Merge pull request #117 from imcaizheng/allow-setting-status-during-creation
[1.5] allow setting status during Job/JobCandidate/ResourceBooking creation
2 parents 5fda963 + ffd1a2f commit cceef5d

File tree

6 files changed

+34
-5
lines changed

6 files changed

+34
-5
lines changed

docs/swagger.yaml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1760,6 +1760,11 @@ components:
17601760
example: "Dummy title"
17611761
description: "The title."
17621762
maxLength: 64
1763+
status:
1764+
type: string
1765+
enum: ['sourcing', 'in-review', 'assigned', 'closed', 'cancelled']
1766+
description: "The job status."
1767+
default: sourcing
17631768
startDate:
17641769
type: string
17651770
format: date-time
@@ -1855,6 +1860,11 @@ components:
18551860
format: uuid
18561861
example: "a55fe1bc-1754-45fa-9adc-cf3d6d7c377a"
18571862
description: "The user id."
1863+
status:
1864+
type: string
1865+
enum: ['open', 'selected', 'shortlist', 'rejected', 'cancelled']
1866+
description: "The job candidate status."
1867+
default: open
18581868
externalId:
18591869
type: string
18601870
example: "1212"
@@ -2009,6 +2019,11 @@ components:
20092019
type: string
20102020
format: uuid
20112021
description: "The job id."
2022+
status:
2023+
type: string
2024+
enum: ['sourcing', 'in-review', 'assigned', 'closed', 'cancelled']
2025+
description: "The job status."
2026+
default: sourcing
20122027
startDate:
20132028
type: string
20142029
format: date-time

src/eventHandlers/ResourceBookingEventHandler.js

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
*/
44

55
const { Op } = require('sequelize')
6+
const _ = require('lodash')
67
const models = require('../models')
78
const logger = require('../common/logger')
89
const helper = require('../common/helper')
@@ -18,7 +19,7 @@ const JobCandidateService = require('../services/JobCandidateService')
1819
* @returns {undefined}
1920
*/
2021
async function selectJobCandidate (payload) {
21-
if (payload.value.status === payload.options.oldValue.status) {
22+
if (_.get(payload, 'options.oldValue') && payload.value.status === payload.options.oldValue.status) {
2223
logger.debug({
2324
component: 'ResourceBookingEventHandler',
2425
context: 'selectJobCandidate',
@@ -73,7 +74,7 @@ async function selectJobCandidate (payload) {
7374
* @returns {undefined}
7475
*/
7576
async function assignJob (payload) {
76-
if (payload.value.status === payload.options.oldValue.status) {
77+
if (_.get(payload, 'options.oldValue') && payload.value.status === payload.options.oldValue.status) {
7778
logger.debug({
7879
component: 'ResourceBookingEventHandler',
7980
context: 'assignJob',
@@ -125,6 +126,17 @@ async function assignJob (payload) {
125126
}
126127
}
127128

129+
/**
130+
* Process resource booking create event.
131+
*
132+
* @param {Object} payload the event payload
133+
* @returns {undefined}
134+
*/
135+
async function processCreate (payload) {
136+
await selectJobCandidate(payload)
137+
await assignJob(payload)
138+
}
139+
128140
/**
129141
* Process resource booking update event.
130142
*
@@ -137,5 +149,6 @@ async function processUpdate (payload) {
137149
}
138150

139151
module.exports = {
152+
processCreate,
140153
processUpdate
141154
}

src/eventHandlers/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ const logger = require('../common/logger')
1212
const TopicOperationMapping = {
1313
[config.TAAS_JOB_UPDATE_TOPIC]: JobEventHandler.processUpdate,
1414
[config.TAAS_JOB_CANDIDATE_CREATE_TOPIC]: JobCandidateEventHandler.processCreate,
15+
[config.TAAS_RESOURCE_BOOKING_CREATE_TOPIC]: ResourceBookingEventHandler.processCreate,
1516
[config.TAAS_RESOURCE_BOOKING_UPDATE_TOPIC]: ResourceBookingEventHandler.processUpdate
1617
}
1718

src/services/JobCandidateService.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,6 @@ async function createJobCandidate (currentUser, jobCandidate) {
9292
jobCandidate.id = uuid()
9393
jobCandidate.createdAt = new Date()
9494
jobCandidate.createdBy = await helper.getUserId(currentUser.userId)
95-
jobCandidate.status = 'open'
9695

9796
const created = await JobCandidate.create(jobCandidate)
9897
await helper.postEvent(config.TAAS_JOB_CANDIDATE_CREATE_TOPIC, jobCandidate)
@@ -102,6 +101,7 @@ async function createJobCandidate (currentUser, jobCandidate) {
102101
createJobCandidate.schema = Joi.object().keys({
103102
currentUser: Joi.object().required(),
104103
jobCandidate: Joi.object().keys({
104+
status: Joi.jobCandidateStatus().default('open'),
105105
jobId: Joi.string().uuid().required(),
106106
userId: Joi.string().uuid().required(),
107107
externalId: Joi.string(),

src/services/JobService.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,6 @@ async function createJob (currentUser, job) {
152152
job.id = uuid()
153153
job.createdAt = new Date()
154154
job.createdBy = await helper.getUserId(currentUser.userId)
155-
job.status = 'sourcing'
156155

157156
const created = await Job.create(job)
158157
await helper.postEvent(config.TAAS_JOB_CREATE_TOPIC, job)
@@ -162,6 +161,7 @@ async function createJob (currentUser, job) {
162161
createJob.schema = Joi.object().keys({
163162
currentUser: Joi.object().required(),
164163
job: Joi.object().keys({
164+
status: Joi.jobStatus().default('sourcing'),
165165
projectId: Joi.number().integer().required(),
166166
externalId: Joi.string(),
167167
description: Joi.string(),

src/services/ResourceBookingService.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,6 @@ async function createResourceBooking (currentUser, resourceBooking) {
105105
resourceBooking.id = uuid()
106106
resourceBooking.createdAt = new Date()
107107
resourceBooking.createdBy = await helper.getUserId(currentUser.userId)
108-
resourceBooking.status = 'sourcing'
109108

110109
const created = await ResourceBooking.create(resourceBooking)
111110
await helper.postEvent(config.TAAS_RESOURCE_BOOKING_CREATE_TOPIC, resourceBooking)
@@ -115,6 +114,7 @@ async function createResourceBooking (currentUser, resourceBooking) {
115114
createResourceBooking.schema = Joi.object().keys({
116115
currentUser: Joi.object().required(),
117116
resourceBooking: Joi.object().keys({
117+
status: Joi.jobStatus().default('sourcing'),
118118
projectId: Joi.number().integer().required(),
119119
userId: Joi.string().uuid().required(),
120120
jobId: Joi.string().uuid(),

0 commit comments

Comments
 (0)