Skip to content

Commit 22e9ebf

Browse files
migration scripts update
1 parent 5d05945 commit 22e9ebf

File tree

1 file changed

+20
-8
lines changed

1 file changed

+20
-8
lines changed

scripts/withdrawn-migration/backup.js

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,25 @@ 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+
// ignore the error
30+
}
31+
if (!job) continue
32+
let rb = null
33+
try {
34+
rb = await ResourceBooking.findOne({
35+
where: {
36+
userId: jc.userId,
37+
jobId: jc.jobId
38+
}
39+
})
40+
} catch (error) {
41+
// ignore the error
42+
}
43+
if (!rb) continue
3244
let completed = false
3345
if (rb && rb.endDate) {
3446
completed = new Date(rb.endDate) < new Date() && new Date(rb.endDate).toDateString() !== new Date().toDateString()
@@ -42,7 +54,7 @@ async function backup () {
4254
where: filter
4355
})
4456
if (candidates && candidates.length > 0) {
45-
fs.writeFile(filePath + `jobcandidate-backup.json`, JSON.stringify(
57+
fs.writeFile(filePath + 'jobcandidate-backup.json', JSON.stringify(
4658
candidates
4759
), (err) => {
4860
if (!err) {

0 commit comments

Comments
 (0)