Skip to content
Merged
Show file tree
Hide file tree
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
3 changes: 2 additions & 1 deletion data/demo-data.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@
"createdBy": "57646ff9-1cd3-4d3c-88ba-eb09a395366c",
"updatedBy": "00000000-0000-0000-0000-000000000000",
"createdAt": "2021-05-09T21:21:10.394Z",
"updatedAt": "2021-05-09T21:21:14.010Z"
"updatedAt": "2021-05-09T21:21:14.010Z",
"rcrmStatus": "Open"
},
{
"id": "728ff056-63f6-4730-8a9f-3074acad8479",
Expand Down
5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,10 @@
"migrate:restore-withdrawn": "node scripts/withdrawn-migration/restore.js",
"migrate:backup-rcrm-status": "node scripts/job-rcrm-status-migration/backup.js",
"migrate:migration-rcrm-status": "node scripts/job-rcrm-status-migration/migration.js",
"migrate:restore-rcrm-status": "node scripts/job-rcrm-status-migration/restore.js"
"migrate:restore-rcrm-status": "node scripts/job-rcrm-status-migration/restore.js",
"migrate:backup-rcrm-status-v2": "node scripts/job-rcrm-status-migration-v2/backup.js",
"migrate:migration-rcrm-status-v2": "node scripts/job-rcrm-status-migration-v2/migration.js",
"migrate:restore-rcrm-status-v2": "node scripts/job-rcrm-status-migration-v2/restore.js"
},
"keywords": [],
"author": "",
Expand Down
52 changes: 52 additions & 0 deletions scripts/job-rcrm-status-migration-v2/backup.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/**
* Back up the jobs that we will update it's status
*/
const fs = require('fs')
const path = require('path')
const request = require('superagent')
const { Job } = require('../../src/models')
const logger = require('../../src/common/logger')

const currentStep = 'Backup'

async function backup () {
logger.info({ component: currentStep, message: '*************************** Backup process started ***************************' })
const filePath = path.join(__dirname, '/temp/')
if (fs.existsSync(filePath)) {
fs.rmdirSync(filePath, { recursive: true })
}
fs.mkdirSync(filePath)
let { body: jobs } = await request.get('https://www.topcoder-dev.com/api/recruit/jobs?job_status=1')
jobs = jobs.map((item) => item.slug)
const backupJobs = []
if (jobs && jobs.length > 0) {
try {
const jbsInDb = await Job.findAll({
where: { rcrmStatus: 'Open' }
})
for (const j of jbsInDb) {
if (jobs.indexOf(j.externalId) < 0) {
// The open job exists in taas but not showing up on Community-App
backupJobs.push(j.externalId)
}
}
fs.writeFileSync(filePath + 'jobs-backup.json', JSON.stringify(
backupJobs
))
logger.info({ component: `${currentStep} Sub`, message: `There are ${backupJobs.length} jobs that need to be updated` })
} catch (err) {
logger.error({ component: currentStep, message: err.message })
process.exit(1)
}
}
logger.info({ component: `${currentStep}`, message: `Report: there are ${backupJobs.length} jobs in total` })
logger.info({ component: currentStep, message: '*************************** Backup process finished ***************************' })
}

backup().then(() => {
logger.info({ component: currentStep, message: 'Execution Finished!' })
process.exit()
}).catch(err => {
logger.error(err.message)
process.exit(1)
})
49 changes: 49 additions & 0 deletions scripts/job-rcrm-status-migration-v2/migration.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/**
* Migration the job rcrm status into Open status
*/
const fs = require('fs')
const path = require('path')
const { Job } = require('../../src/models')
const logger = require('../../src/common/logger')

const currentStep = 'Migration'

async function migration () {
logger.info({ component: currentStep, message: '*************************** Migration process started ***************************' })
const filePath = path.join(__dirname, '/temp/')
const files = []
fs.readdirSync(filePath).forEach(async (file) => {
files.push(`${filePath}${file}`)
})
let totalSum = 0
for (let j = 0; j < files.length; j++) {
const data = fs.readFileSync(files[j], 'utf-8')
const rcrmIds = JSON.parse(data)
let summary = 0
for (let i = 0; i < rcrmIds.length; i++) {
const jbs = await Job.findAll({
where: { externalId: rcrmIds[i] }
})
for (let j = 0; j < jbs.length; j++) {
if (jbs[j]) {
const oldStatus = jbs[j].rcrmStatus
const updated = await jbs[j].update({ rcrmStatus: null })
summary++
totalSum++
logger.info({ component: currentStep, message: `job with rcrmId ${rcrmIds[i]} status changed from ${oldStatus} to ${updated.rcrmStatus}` })
}
}
};
logger.info({ component: `${currentStep} Sub`, message: `Updated ${summary} jobs from ${files[j]}` })
}
logger.info({ component: currentStep, message: `Report: Totally Updated ${totalSum} jobs` })
logger.info({ component: currentStep, message: '*************************** Migration process finished ***************************' })
}

migration().then(() => {
logger.info({ component: currentStep, message: 'Execution Finished!' })
process.exit()
}).catch(err => {
logger.error(err.message)
process.exit(1)
})
49 changes: 49 additions & 0 deletions scripts/job-rcrm-status-migration-v2/restore.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/**
* Restore the job rcrm status into Open status
*/
const fs = require('fs')
const path = require('path')
const { Job } = require('../../src/models')
const logger = require('../../src/common/logger')

const currentStep = 'Restore'

async function restore () {
logger.info({ component: currentStep, message: '*************************** Restore process started ***************************' })
const filePath = path.join(__dirname, '/temp/')
const files = []
fs.readdirSync(filePath).forEach(async (file) => {
files.push(`${filePath}${file}`)
})
let totalSum = 0
for (let j = 0; j < files.length; j++) {
const data = fs.readFileSync(files[j], 'utf-8')
const rcrmIds = JSON.parse(data)
let summary = 0
for (let i = 0; i < rcrmIds.length; i++) {
const jbs = await Job.findAll({
where: { externalId: rcrmIds[i] }
})
for (let j = 0; j < jbs.length; j++) {
if (jbs[j]) {
const oldStatus = jbs[j].rcrmStatus
const updated = await jbs[j].update({ rcrmStatus: 'Open' })
summary++
totalSum++
logger.info({ component: currentStep, message: `job with rcrmId ${rcrmIds[i]} status changed from ${oldStatus} to ${updated.rcrmStatus}` })
}
}
};
logger.info({ component: `${currentStep} Sub`, message: `Updated ${summary} jobs from ${files[j]}` })
}
logger.info({ component: currentStep, message: `Report: Totally Restored ${totalSum} jobs` })
logger.info({ component: currentStep, message: '*************************** Restore process finished ***************************' })
}

restore().then(() => {
logger.info({ component: currentStep, message: 'Execution Finished!' })
process.exit()
}).catch(err => {
logger.error(err.message)
process.exit(1)
})
1 change: 1 addition & 0 deletions scripts/job-rcrm-status-migration-v2/temp/jobs-backup.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
["88774632"]