Skip to content

Commit ab77c3f

Browse files
Merge pull request #95 from imcaizheng/job-add-title-field
add the title field to Job model
2 parents b548040 + 28891fd commit ab77c3f

File tree

7 files changed

+161
-215
lines changed

7 files changed

+161
-215
lines changed

docs/Topcoder-bookings-api.postman_collection.json

Lines changed: 107 additions & 214 deletions
Large diffs are not rendered by default.

docs/swagger.yaml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,13 @@ paths:
125125
schema:
126126
type: string
127127
description: The description.
128+
- in: query
129+
name: title
130+
required: false
131+
schema:
132+
type: string
133+
maxLength: 64
134+
description: The title.
128135
- in: query
129136
name: startDate
130137
required: false
@@ -1613,6 +1620,7 @@ components:
16131620
- projectId
16141621
- externalId
16151622
- description
1623+
- title
16161624
- startDate
16171625
- endDate
16181626
- numPositions
@@ -1639,6 +1647,11 @@ components:
16391647
type: string
16401648
example: "Dummy Description"
16411649
description: "The description."
1650+
title:
1651+
type: string
1652+
example: "Dummy title"
1653+
description: "The title."
1654+
maxLength: 64
16421655
startDate:
16431656
type: string
16441657
format: date-time
@@ -1702,6 +1715,7 @@ components:
17021715
- projectId
17031716
- externalId
17041717
- description
1718+
- title
17051719
- startDate
17061720
- endDate
17071721
- numPositions
@@ -1721,6 +1735,11 @@ components:
17211735
type: string
17221736
example: "Dummy Description"
17231737
description: "The description."
1738+
title:
1739+
type: string
1740+
example: "Dummy title"
1741+
description: "The title."
1742+
maxLength: 64
17241743
startDate:
17251744
type: string
17261745
format: date-time
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
/*
2+
* Add title field to the Job model.
3+
*/
4+
5+
module.exports = {
6+
up: queryInterface => {
7+
return Promise.all([
8+
queryInterface.sequelize.query('ALTER TABLE bookings.jobs ADD title VARCHAR(64)'),
9+
queryInterface.sequelize.query('UPDATE bookings.jobs SET title=description WHERE title is NULL'),
10+
queryInterface.sequelize.query('ALTER TABLE bookings.jobs ALTER COLUMN title SET NOT NULL')
11+
])
12+
},
13+
down: queryInterface => {
14+
return Promise.all([
15+
queryInterface.sequelize.query('ALTER TABLE bookings.jobs DROP title')
16+
])
17+
}
18+
}

scripts/createIndex.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ async function createIndex () {
1818
projectId: { type: 'integer' },
1919
externalId: { type: 'keyword' },
2020
description: { type: 'text' },
21+
title: { type: 'text' },
2122
startDate: { type: 'date' },
2223
endDate: { type: 'date' },
2324
numPositions: { type: 'integer' },

src/bootstrap.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ Joi.rateType = () => Joi.string().valid('hourly', 'daily', 'weekly', 'monthly')
99
Joi.jobStatus = () => Joi.string().valid('sourcing', 'in-review', 'assigned', 'closed', 'cancelled')
1010
Joi.workload = () => Joi.string().valid('full-time', 'fractional')
1111
Joi.jobCandidateStatus = () => Joi.string().valid('open', 'selected', 'shortlist', 'rejected', 'cancelled')
12+
Joi.title = () => Joi.string().max(64)
1213

1314
function buildServices (dir) {
1415
const files = fs.readdirSync(dir)

src/models/Job.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,10 @@ module.exports = (sequelize) => {
7373
type: Sequelize.STRING,
7474
allowNull: false
7575
},
76+
title: {
77+
type: Sequelize.STRING,
78+
allowNull: false
79+
},
7680
startDate: {
7781
field: 'start_date',
7882
type: Sequelize.DATE,

src/services/JobService.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,7 @@ createJob.schema = Joi.object().keys({
165165
projectId: Joi.number().integer().required(),
166166
externalId: Joi.string().required(),
167167
description: Joi.string().required(),
168+
title: Joi.title().required(),
168169
startDate: Joi.date().required(),
169170
endDate: Joi.date().required(),
170171
numPositions: Joi.number().integer().min(1).required(),
@@ -225,6 +226,7 @@ partiallyUpdateJob.schema = Joi.object().keys({
225226
data: Joi.object().keys({
226227
status: Joi.jobStatus(),
227228
description: Joi.string(),
229+
title: Joi.title(),
228230
startDate: Joi.date(),
229231
endDate: Joi.date(),
230232
numPositions: Joi.number().integer().min(1),
@@ -253,6 +255,7 @@ fullyUpdateJob.schema = Joi.object().keys({
253255
projectId: Joi.number().integer().required(),
254256
externalId: Joi.string().required(),
255257
description: Joi.string().required(),
258+
title: Joi.title().required(),
256259
startDate: Joi.date().required(),
257260
endDate: Joi.date().required(),
258261
numPositions: Joi.number().integer().min(1).required(),
@@ -347,10 +350,11 @@ async function searchJobs (currentUser, criteria, options = { returnAll: false }
347350
'skill',
348351
'rateType',
349352
'workload',
353+
'title',
350354
'status'
351355
]), (value, key) => {
352356
let must
353-
if (key === 'description') {
357+
if (key === 'description' || key === 'title') {
354358
must = {
355359
match: {
356360
[key]: {
@@ -426,6 +430,11 @@ async function searchJobs (currentUser, criteria, options = { returnAll: false }
426430
[Op.like]: `%${criteria.description}%`
427431
}
428432
}
433+
if (criteria.title) {
434+
filter.title = {
435+
[Op.like]: `%${criteria.title}%`
436+
}
437+
}
429438
if (criteria.skills) {
430439
filter.skills = {
431440
[Op.contains]: [criteria.skills]
@@ -470,6 +479,7 @@ searchJobs.schema = Joi.object().keys({
470479
projectId: Joi.number().integer(),
471480
externalId: Joi.string(),
472481
description: Joi.string(),
482+
title: Joi.title(),
473483
startDate: Joi.date(),
474484
endDate: Joi.date(),
475485
resourceType: Joi.string(),

0 commit comments

Comments
 (0)