Skip to content

Additional Fix for the migration jobCandidates #448

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Aug 4, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 22 additions & 8 deletions scripts/withdrawn-migration/backup.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,27 @@ async function backup () {

for (let i = 0; i < jobCandidates.length; i++) {
const jc = jobCandidates[i]
const job = await Job.findById(jc.jobId)
const rb = await ResourceBooking.findOne({
where: {
userId: jc.userId,
jobId: jc.jobId
}
})
let job = null
try {
job = await Job.findById(jc.jobId)
} catch (error) {
// log the error
logger.info({ component: currentStep, message: `==> Data integrity issue: Can't find the Job with Id ${jc.jobId}` })
}
if (!job) continue
let rb = null
try {
rb = await ResourceBooking.findOne({
where: {
userId: jc.userId,
jobId: jc.jobId
}
})
} catch (error) {
// log the error
logger.info({ component: currentStep, message: `==> Data integrity issue: Can't find the ResourceBooking whose userId is ${jc.userId} and jobId is ${jc.jobId}` })
}
if (!rb) continue
let completed = false
if (rb && rb.endDate) {
completed = new Date(rb.endDate) < new Date() && new Date(rb.endDate).toDateString() !== new Date().toDateString()
Expand All @@ -42,7 +56,7 @@ async function backup () {
where: filter
})
if (candidates && candidates.length > 0) {
fs.writeFile(filePath + `jobcandidate-backup.json`, JSON.stringify(
fs.writeFile(filePath + 'jobcandidate-backup.json', JSON.stringify(
candidates
), (err) => {
if (!err) {
Expand Down