Skip to content

add the title field to Job model #95

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
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
321 changes: 107 additions & 214 deletions docs/Topcoder-bookings-api.postman_collection.json

Large diffs are not rendered by default.

19 changes: 19 additions & 0 deletions docs/swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,13 @@ paths:
schema:
type: string
description: The description.
- in: query
name: title
required: false
schema:
type: string
maxLength: 64
description: The title.
- in: query
name: startDate
required: false
Expand Down Expand Up @@ -1613,6 +1620,7 @@ components:
- projectId
- externalId
- description
- title
- startDate
- endDate
- numPositions
Expand All @@ -1639,6 +1647,11 @@ components:
type: string
example: "Dummy Description"
description: "The description."
title:
type: string
example: "Dummy title"
description: "The title."
maxLength: 64
startDate:
type: string
format: date-time
Expand Down Expand Up @@ -1702,6 +1715,7 @@ components:
- projectId
- externalId
- description
- title
- startDate
- endDate
- numPositions
Expand All @@ -1721,6 +1735,11 @@ components:
type: string
example: "Dummy Description"
description: "The description."
title:
type: string
example: "Dummy title"
description: "The title."
maxLength: 64
startDate:
type: string
format: date-time
Expand Down
18 changes: 18 additions & 0 deletions migrations/2021-01-06-job-add-title-field.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/*
* Add title field to the Job model.
*/

module.exports = {
up: queryInterface => {
return Promise.all([
queryInterface.sequelize.query('ALTER TABLE bookings.jobs ADD title VARCHAR(64)'),
queryInterface.sequelize.query('UPDATE bookings.jobs SET title=description WHERE title is NULL'),
queryInterface.sequelize.query('ALTER TABLE bookings.jobs ALTER COLUMN title SET NOT NULL')
])
},
down: queryInterface => {
return Promise.all([
queryInterface.sequelize.query('ALTER TABLE bookings.jobs DROP title')
])
}
}
1 change: 1 addition & 0 deletions scripts/createIndex.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ async function createIndex () {
projectId: { type: 'integer' },
externalId: { type: 'keyword' },
description: { type: 'text' },
title: { type: 'text' },
startDate: { type: 'date' },
endDate: { type: 'date' },
numPositions: { type: 'integer' },
Expand Down
1 change: 1 addition & 0 deletions src/bootstrap.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ Joi.rateType = () => Joi.string().valid('hourly', 'daily', 'weekly', 'monthly')
Joi.jobStatus = () => Joi.string().valid('sourcing', 'in-review', 'assigned', 'closed', 'cancelled')
Joi.workload = () => Joi.string().valid('full-time', 'fractional')
Joi.jobCandidateStatus = () => Joi.string().valid('open', 'selected', 'shortlist', 'rejected', 'cancelled')
Joi.title = () => Joi.string().max(64)

function buildServices (dir) {
const files = fs.readdirSync(dir)
Expand Down
4 changes: 4 additions & 0 deletions src/models/Job.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,10 @@ module.exports = (sequelize) => {
type: Sequelize.STRING,
allowNull: false
},
title: {
type: Sequelize.STRING,
allowNull: false
},
startDate: {
field: 'start_date',
type: Sequelize.DATE,
Expand Down
12 changes: 11 additions & 1 deletion src/services/JobService.js
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@ createJob.schema = Joi.object().keys({
projectId: Joi.number().integer().required(),
externalId: Joi.string().required(),
description: Joi.string().required(),
title: Joi.title().required(),
startDate: Joi.date().required(),
endDate: Joi.date().required(),
numPositions: Joi.number().integer().min(1).required(),
Expand Down Expand Up @@ -225,6 +226,7 @@ partiallyUpdateJob.schema = Joi.object().keys({
data: Joi.object().keys({
status: Joi.jobStatus(),
description: Joi.string(),
title: Joi.title(),
startDate: Joi.date(),
endDate: Joi.date(),
numPositions: Joi.number().integer().min(1),
Expand Down Expand Up @@ -253,6 +255,7 @@ fullyUpdateJob.schema = Joi.object().keys({
projectId: Joi.number().integer().required(),
externalId: Joi.string().required(),
description: Joi.string().required(),
title: Joi.title().required(),
startDate: Joi.date().required(),
endDate: Joi.date().required(),
numPositions: Joi.number().integer().min(1).required(),
Expand Down Expand Up @@ -347,10 +350,11 @@ async function searchJobs (currentUser, criteria, options = { returnAll: false }
'skill',
'rateType',
'workload',
'title',
'status'
]), (value, key) => {
let must
if (key === 'description') {
if (key === 'description' || key === 'title') {
must = {
match: {
[key]: {
Expand Down Expand Up @@ -426,6 +430,11 @@ async function searchJobs (currentUser, criteria, options = { returnAll: false }
[Op.like]: `%${criteria.description}%`
}
}
if (criteria.title) {
filter.title = {
[Op.like]: `%${criteria.title}%`
}
}
if (criteria.skills) {
filter.skills = {
[Op.contains]: [criteria.skills]
Expand Down Expand Up @@ -470,6 +479,7 @@ searchJobs.schema = Joi.object().keys({
projectId: Joi.number().integer(),
externalId: Joi.string(),
description: Joi.string(),
title: Joi.title(),
startDate: Joi.date(),
endDate: Joi.date(),
resourceType: Joi.string(),
Expand Down