@@ -20,9 +20,9 @@ const localLogger = {
2020 * @param {Object } message the message object
2121 * @returns {undefined }
2222 */
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 } ` } )
2626 return
2727 }
2828 if ( ! [ 'rejected' , 'shortlist' ] . includes ( payload . status ) ) {
@@ -56,13 +56,13 @@ async function updateCandidateStatus ({ type, payload }) {
5656 * @param {Object } message the message object
5757 * @returns {undefined }
5858 */
59- async function postMessageToZapier ( { type, payload } ) {
59+ async function postMessageToZapier ( { type, payload, previousData } ) {
6060 if ( config . zapier . ZAPIER_JOB_CANDIDATE_SWITCH === constants . Zapier . Switch . OFF ) {
6161 localLogger . debug ( { context : 'postMessageToZapier' , message : 'Zapier Switch off via config, no messages sent' } )
6262 return
6363 }
6464 if ( type === constants . Zapier . MessageType . JobCandidateUpdate ) {
65- await updateCandidateStatus ( { type, payload } )
65+ await updateCandidateStatus ( { type, payload, previousData } )
6666 return
6767 }
6868 throw new Error ( `unrecognized message type: ${ type } ` )
@@ -113,6 +113,12 @@ processCreate.schema = {
113113 */
114114async function processUpdate ( message , transactionId ) {
115115 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+ } )
116122 await esClient . updateExtra ( {
117123 index : config . get ( 'esConfig.ES_INDEX_JOB_CANDIDATE' ) ,
118124 id : data . id ,
@@ -124,7 +130,8 @@ async function processUpdate (message, transactionId) {
124130 } )
125131 await postMessageToZapier ( {
126132 type : constants . Zapier . MessageType . JobCandidateUpdate ,
127- payload : data
133+ payload : data ,
134+ previousData
128135 } )
129136}
130137
0 commit comments