33 */
44
55const { Op } = require ( 'sequelize' )
6+ const _ = require ( 'lodash' )
67const models = require ( '../models' )
78const logger = require ( '../common/logger' )
89const helper = require ( '../common/helper' )
@@ -18,7 +19,7 @@ const JobCandidateService = require('../services/JobCandidateService')
1819 * @returns {undefined }
1920 */
2021async 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 */
7576async 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
139151module . exports = {
152+ processCreate,
140153 processUpdate
141154}
0 commit comments