Skip to content

[Ready Release] Gigs Listing - RCRM Status Sync #579

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 20 commits into from
Oct 25, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
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
1 change: 1 addition & 0 deletions data/demo-data.json
Original file line number Diff line number Diff line change
Expand Up @@ -1325,6 +1325,7 @@
"externalId": "300234321",
"resume": "http://example.com",
"remark": "excellent",
"featured": null,
"createdBy": "00000000-0000-0000-0000-000000000000",
"updatedBy": "00000000-0000-0000-0000-000000000000",
"createdAt": "2021-05-09T21:15:02.183Z",
Expand Down
56 changes: 56 additions & 0 deletions docs/swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,18 @@ paths:
schema:
type: boolean
description: When passing true, the API will load all featured and showInHotList jobs at once
- in: query
name: featured
required: false
schema:
type: boolean
description: The featured jobs
- in: query
name: rcrmStatus
required: false
schema:
type: string
enum: ["Open", "On Hold", "Canceled", "Draft", "Closed"]
requestBody:
content:
application/json:
Expand Down Expand Up @@ -4122,6 +4134,32 @@ components:
type: string
example: "USD"
description: "the currency of job"
showInHotList:
type: boolean
default: false
description: "Whether to show job in hot list"
featured:
type: boolean
default: false
description: "Whether a job is a featured job"
hotListExcerpt:
type: string
default: ''
description: "A text to show for the hotlist excerpt"
jobTag:
type: string
default: ''
enum: ["New", "$$$", "Hot", ""]
description: "the job tag"
rcrmStatus:
type: string
default: null
enum: [null, "Open", "On Hold", "Canceled", "Draft", "Closed"]
description: "the job rcrm status"
rcrmReason:
type: string
default: null
description: "the possible rcrm reason for current status"
createdAt:
type: string
format: date-time
Expand Down Expand Up @@ -4241,6 +4279,15 @@ components:
type: string
enum: ["", "New", "$$$", "Hot"]
description: "The tag of a job"
rcrmStatus:
type: string
default: null
enum: [null, "Open", "On Hold", "Canceled", "Draft", "Closed"]
description: "the job rcrm status"
rcrmReason:
type: string
default: null
description: "the possible rcrm reason for current status"
isApplicationPageActive:
type: boolean
default: false
Expand Down Expand Up @@ -4797,6 +4844,15 @@ components:
type: string
enum: ["", "New", "$$$", "Hot"]
description: "The tag of a job"
rcrmStatus:
type: string
default: null
enum: [null, "Open", "On Hold", "Canceled", "Draft", "Closed"]
description: "the job rcrm status"
rcrmReason:
type: string
default: null
description: "the possible rcrm reason for current status"
isApplicationPageActive:
type: boolean
default: false
Expand Down
2 changes: 1 addition & 1 deletion local/kafka-client/topics.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,4 @@ taas.interview.update
taas.interview.bulkUpdate
external.action.email
taas.action.retry
notifications.action.create
notifications.action.create
37 changes: 37 additions & 0 deletions migrations/2021-10-14-job-add-job-rcrm-status.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
const config = require('config')

/*
* Add rcrm_status, rcrm_reason to the Job model.
type: Sequelize.STRING(255),
defaultValue: null,
allowNull: true
*/

module.exports = {
up: async (queryInterface, Sequelize) => {
const transaction = await queryInterface.sequelize.transaction()
try {
await queryInterface.addColumn({ tableName: 'jobs', schema: config.DB_SCHEMA_NAME }, 'rcrm_status',
{ type: Sequelize.STRING(255), allowNull: true, defaultValue: null },
{ transaction })
await queryInterface.addColumn({ tableName: 'jobs', schema: config.DB_SCHEMA_NAME }, 'rcrm_reason',
{ type: Sequelize.STRING(255), allowNull: true, defaultValue: null },
{ transaction })
await transaction.commit()
} catch (err) {
await transaction.rollback()
throw err
}
},
down: async (queryInterface, Sequelize) => {
const transaction = await queryInterface.sequelize.transaction()
try {
await queryInterface.removeColumn({ tableName: 'jobs', schema: config.DB_SCHEMA_NAME }, 'rcrm_status', { transaction })
await queryInterface.removeColumn({ tableName: 'jobs', schema: config.DB_SCHEMA_NAME }, 'rcrm_reason', { transaction })
await transaction.commit()
} catch (err) {
await transaction.rollback()
throw err
}
}
}
5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,10 @@
"demo-payment": "node scripts/demo-payment",
"migrate:backup-withdrawn": "node scripts/withdrawn-migration/backup.js",
"migrate:migration-withdrawn": "node scripts/withdrawn-migration/migration.js",
"migrate:restore-withdrawn": "node scripts/withdrawn-migration/restore.js"
"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"
},
"keywords": [],
"author": "",
Expand Down
41 changes: 41 additions & 0 deletions scripts/job-rcrm-status-migration/backup.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/**
* Back up the jobs that we will update it's status
*/
const fs = require('fs')
const path = require('path')
const request = require('superagent')
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)
if (jobs && jobs.length > 0) {
try {
fs.writeFileSync(filePath + 'jobs-backup.json', JSON.stringify(
jobs
))
logger.info({ component: `${currentStep} Sub`, message: `There are ${jobs.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 ${jobs.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/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: '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 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/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: 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 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/temp/jobs-backup.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
["90269852","28960960","16341500556800013350dQL","16341323722130013350Qgs","16341323715070013350yCX","16341501858830013350JSx","16342073365140013350Omh","16342071086360013350TKd","29014265","16341982292150013350DhE","16341851836400013350YSd","16341851823530013350OHa","16341323716640013350BFn","16341517864620013350LvZ","16341438759150013350CTj","16341414354520013350czx","16329389793410013350nhr","16341285133710013350gRv","16327915384700013350wjq","16322342157030013350thK","16340504449290013350Zmk","16336199677990013350hWP","16340663860380013350dkg","16323945983630013350VIn","16340663745860013350Ogp","16340521190520013350Zyo","16329256769300013350wOD","16330142450080013350Zud","16336147040350013350Nbe","16335218110630009830oSa","16328384519390013350hzK","16337227842100013350BDn","16328401153230013350dVH","16339568564580013350cxO","16337126130130013350GNX","16337229047900013350rlK","16339461887230013350pHA","16339455520130013350SMw","16292946209270013350cqL","16317343900830013350iSB","16334323145940013350bqN","16333532888560013350VfJ","16335231874280013350PsN","16335233245550013350ybF","16335365496710013350mdw","16324274043560013350per","28968572","16328235118630013350TUH","16329413634180013350cbO","89425274","16322224121530013350BxF","16335010800170013350OlD","16335010785580013350ZMW","16335010794140013350qSN","16335010771830013350kvN","16335010773590013350kyi","16329269383370013350pcK","16334453262680013350ksT","16317088129440013350Yuq","16333604284300013350scM","16334117377520013350lxQ","16334117503830013350mot","16334040093120013350uQK","16333472255660013350DMW","16322834774440013350qgN","16322398868710013350TVc","16333463496610013350hPf","16333296533550013350VMv","16311102743050013350UOQ","16305004931790013350nDf","16329484262990013350Lxj","16329780377000013350gjy","16321575158770013350aMr","16330154680980013350guh","16330154680330013350xSz","16330153298270013350azs","16317282228550013350KNM","16329976194830013350YeO","16329926004110013350tBA","16329780351410013350mLA","16305004990960013350Ssa","16325262321460013350SVA","16311098213960013350dOG","89264852","16322413567270013350DGr","16305004975190013350PFT","16309630704830013350hEg","16328129817130013350NAX","16328127653330013350DdA","16328123904580013350LUi","16328103721410013350tQw","16328099924470013350xAs","90068402","16327519095440013350Pxc","16327519083280013350ehu","16327406515900013350pkn","16324784697460013350zYO","16327120198060013350ncx","16326943991890013350CEP","27288460","16311191494770013350NUc","16313030794420013350jid","16313049677110013350DaN","16311326832280013350lHd","16323409561830013350sZU","16323378537470013350LEP","16312171350470013350JFb","16322398849240013350gPZ","16318012800890013350XTH","16323155626160013350sIH","28317595","16318000891270013350pVC","16322398874030013350dvM","29006647","16315538849780013350xOe","16310329298030013350vqT","16311345128210013350uOw","16312910846980013350yXL","16319302023020013350VjQ","16318858946340013350azO","16318858943670013350UyO","16318065232030013350ocm","16317263340200013350OAu","16318005347030013350xIY","89358414","16317823615620013350XTK","16304287461100013350mlf","16317340318160013350Tvh","90162384","16316425217580013350jtR","16317111609390013350kBm","16313011847990013350euT","16316739298570013350ubh","16316427345940013350FdR","16316254338250013350pnL","16315761396170013350NdW","16315527065980013350goJ","16315527103010013350OJR","16315527070820013350lNq","16315377284630013350kKy","16311282358380013350yvA","16311123863240013350poV","16311065501620013350xXk","16297520948230013350jsO","29381105","29121022","16297515193190013350yKq","16307003081530013350IRF","16298349408110013350fVu","16298344596880013350BkO","16306692819950013350PDG","16306692838930013350ZSc","16305973203140013350VLM","16305382326930013350ZIQ","16287824631380013350wvk","90296729","16303059379040013350mEr","16305210643780013350wHi","16298350433530013350pao","16300042451840013350bRI","28604324","29029504","29105759","16285320575270013350CGO","16292061450370013350IBs","29235622","16291317250860013350FZU","16292936844360013350FUf","28877294","90202677","90216110","90417725","29212684","29365774","16286918867350013350JMe","16285323789010013350Eaf","29205040","26759080","16297498617830013350rVR","16297359818350013350zUS","29059994","90471527","16285337043140013350ZKp","16281924024020013350syz","90148955","25996360","89385155","89371784","89518920","89505539","89438649","89398527","29373439"]
1 change: 1 addition & 0 deletions src/bootstrap.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ Joi.page = () => Joi.number().integer().min(1).default(1)
Joi.perPage = () => Joi.number().integer().min(1).default(20)
Joi.rateType = () => Joi.string().valid('hourly', 'daily', 'weekly', 'monthly', 'annual')
Joi.jobStatus = () => Joi.string().valid('sourcing', 'in-review', 'assigned', 'closed', 'cancelled')
Joi.jobRcrmStatus = () => Joi.string().valid('Open', 'On Hold', 'Canceled', 'Draft', 'Closed').allow(null)
Joi.jobTag = () => Joi.string().valid('New', '$$$', 'Hot').allow('')
Joi.resourceBookingStatus = () => Joi.string().valid('placed', 'closed', 'cancelled')
Joi.workload = () => Joi.string().valid('full-time', 'fractional')
Expand Down
12 changes: 12 additions & 0 deletions src/models/Job.js
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,18 @@ module.exports = (sequelize) => {
allowNull: true,
defaultValue: ''
},
rcrmStatus: {
field: 'rcrm_status',
type: Sequelize.STRING(255),
allowNull: true,
defaultValue: null
},
rcrmReason: {
field: 'rcrm_reason',
type: Sequelize.STRING(255),
allowNull: true,
defaultValue: null
},
createdBy: {
field: 'created_by',
type: Sequelize.UUID,
Expand Down
Loading