@@ -20,9 +20,9 @@ const localLogger = {
20
20
* @param {Object } message the message object
21
21
* @returns {undefined }
22
22
*/
23
- async function updateCandidateStatus ( { type, payload } ) {
24
- if ( ! payload . status ) {
25
- localLogger . debug ( { context : 'updateCandidateStatus' , message : 'status not updated' } )
23
+ async function updateCandidateStatus ( { type, payload, previousData } ) {
24
+ if ( previousData . status === payload . status ) {
25
+ localLogger . debug ( { context : 'updateCandidateStatus' , message : `jobCandidate is already in status: ${ payload . status } ` } )
26
26
return
27
27
}
28
28
if ( ! [ 'rejected' , 'shortlist' ] . includes ( payload . status ) ) {
@@ -56,13 +56,13 @@ async function updateCandidateStatus ({ type, payload }) {
56
56
* @param {Object } message the message object
57
57
* @returns {undefined }
58
58
*/
59
- async function postMessageToZapier ( { type, payload } ) {
59
+ async function postMessageToZapier ( { type, payload, previousData } ) {
60
60
if ( config . zapier . ZAPIER_JOB_CANDIDATE_SWITCH === constants . Zapier . Switch . OFF ) {
61
61
localLogger . debug ( { context : 'postMessageToZapier' , message : 'Zapier Switch off via config, no messages sent' } )
62
62
return
63
63
}
64
64
if ( type === constants . Zapier . MessageType . JobCandidateUpdate ) {
65
- await updateCandidateStatus ( { type, payload } )
65
+ await updateCandidateStatus ( { type, payload, previousData } )
66
66
return
67
67
}
68
68
throw new Error ( `unrecognized message type: ${ type } ` )
@@ -113,6 +113,12 @@ processCreate.schema = {
113
113
*/
114
114
async function processUpdate ( message , transactionId ) {
115
115
const data = message . payload
116
+ // save previous data for Zapier logic
117
+ // NOTE: ideally if we update Kafka event message to have both: pervious and updated value so we don't have to request it again
118
+ const { body : previousData } = await esClient . getExtra ( {
119
+ index : config . get ( 'esConfig.ES_INDEX_JOB_CANDIDATE' ) ,
120
+ id : data . id
121
+ } )
116
122
await esClient . updateExtra ( {
117
123
index : config . get ( 'esConfig.ES_INDEX_JOB_CANDIDATE' ) ,
118
124
id : data . id ,
@@ -124,7 +130,8 @@ async function processUpdate (message, transactionId) {
124
130
} )
125
131
await postMessageToZapier ( {
126
132
type : constants . Zapier . MessageType . JobCandidateUpdate ,
127
- payload : data
133
+ payload : data ,
134
+ previousData
128
135
} )
129
136
}
130
137
0 commit comments