Skip to content

Commit 076cc8a

Browse files
committed
fix: don't cancel ResourceBookings
ref issue #54
1 parent 8821b54 commit 076cc8a

File tree

1 file changed

+13
-36
lines changed

1 file changed

+13
-36
lines changed

src/eventHandlers/JobEventHandler.js

Lines changed: 13 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,9 @@ const models = require('../models')
77
const logger = require('../common/logger')
88
const helper = require('../common/helper')
99
const JobCandidateService = require('../services/JobCandidateService')
10-
const ResourceBookingService = require('../services/ResourceBookingService')
1110

1211
/**
13-
* Cancel all related resource bookings and all related candidates when a job is cancelled.
12+
* Cancel all related related candidates when a job is cancelled.
1413
*
1514
* @param {Object} payload the event payload
1615
* @returns {undefined}
@@ -33,7 +32,7 @@ async function cancelJob (payload) {
3332
return
3433
}
3534
// pull data from db instead of directly extract data from the payload
36-
// since the payload may not contain all fields when it is from partically update operation.
35+
// since the payload may not contain all fields when it is from partially update operation.
3736
const job = await models.Job.findById(payload.value.id)
3837
const candidates = await models.JobCandidate.findAll({
3938
where: {
@@ -44,39 +43,17 @@ async function cancelJob (payload) {
4443
deletedAt: null
4544
}
4645
})
47-
const resourceBookings = await models.ResourceBooking.findAll({
48-
where: {
49-
jobId: job.id,
50-
status: {
51-
[Op.not]: 'cancelled'
52-
},
53-
deletedAt: null
54-
}
55-
})
56-
await Promise.all([
57-
...candidates.map(candidate => JobCandidateService.partiallyUpdateJobCandidate(
58-
helper.getAuditM2Muser(),
59-
candidate.id,
60-
{ status: 'cancelled' }
61-
).then(result => {
62-
logger.info({
63-
component: 'JobEventHandler',
64-
context: 'cancelJob',
65-
message: `id: ${result.id} candidate got cancelled.`
66-
})
67-
})),
68-
...resourceBookings.map(resource => ResourceBookingService.partiallyUpdateResourceBooking(
69-
helper.getAuditM2Muser(),
70-
resource.id,
71-
{ status: 'cancelled' }
72-
).then(result => {
73-
logger.info({
74-
component: 'JobEventHandler',
75-
context: 'cancelJob',
76-
message: `id: ${result.id} resource booking got cancelled.`
77-
})
78-
}))
79-
])
46+
await Promise.all(candidates.map(candidate => JobCandidateService.partiallyUpdateJobCandidate(
47+
helper.getAuditM2Muser(),
48+
candidate.id,
49+
{ status: 'cancelled' }
50+
).then(result => {
51+
logger.info({
52+
component: 'JobEventHandler',
53+
context: 'cancelJob',
54+
message: `id: ${result.id} candidate got cancelled.`
55+
})
56+
})))
8057
}
8158

8259
/**

0 commit comments

Comments
 (0)