Skip to content

Commit 965ff50

Browse files
Merge pull request #448 from topcoder-platform/migrate-jobcandidates-scripts
Additional Fix for the migration jobCandidates
2 parents 51a5e62 + d0ea9c8 commit 965ff50

File tree

1 file changed

+22
-8
lines changed

1 file changed

+22
-8
lines changed

scripts/withdrawn-migration/backup.js

+22-8
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,27 @@ async function backup () {
2222

2323
for (let i = 0; i < jobCandidates.length; i++) {
2424
const jc = jobCandidates[i]
25-
const job = await Job.findById(jc.jobId)
26-
const rb = await ResourceBooking.findOne({
27-
where: {
28-
userId: jc.userId,
29-
jobId: jc.jobId
30-
}
31-
})
25+
let job = null
26+
try {
27+
job = await Job.findById(jc.jobId)
28+
} catch (error) {
29+
// log the error
30+
logger.info({ component: currentStep, message: `==> Data integrity issue: Can't find the Job with Id ${jc.jobId}` })
31+
}
32+
if (!job) continue
33+
let rb = null
34+
try {
35+
rb = await ResourceBooking.findOne({
36+
where: {
37+
userId: jc.userId,
38+
jobId: jc.jobId
39+
}
40+
})
41+
} catch (error) {
42+
// log the error
43+
logger.info({ component: currentStep, message: `==> Data integrity issue: Can't find the ResourceBooking whose userId is ${jc.userId} and jobId is ${jc.jobId}` })
44+
}
45+
if (!rb) continue
3246
let completed = false
3347
if (rb && rb.endDate) {
3448
completed = new Date(rb.endDate) < new Date() && new Date(rb.endDate).toDateString() !== new Date().toDateString()
@@ -42,7 +56,7 @@ async function backup () {
4256
where: filter
4357
})
4458
if (candidates && candidates.length > 0) {
45-
fs.writeFile(filePath + `jobcandidate-backup.json`, JSON.stringify(
59+
fs.writeFile(filePath + 'jobcandidate-backup.json', JSON.stringify(
4660
candidates
4761
), (err) => {
4862
if (!err) {

0 commit comments

Comments
 (0)