Skip to content

Commit b0f61b9

Browse files
Merge pull request #103 from imcaizheng/make-some-fields-for-job-optional
make some fields of Job optional
2 parents 8fdd9ef + 4f4ebc1 commit b0f61b9

File tree

4 files changed

+46
-39
lines changed

4 files changed

+46
-39
lines changed

docs/swagger.yaml

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1624,14 +1624,8 @@ components:
16241624
required:
16251625
- id
16261626
- projectId
1627-
- externalId
1628-
- description
16291627
- title
1630-
- startDate
1631-
- endDate
16321628
- numPositions
1633-
- resourceType
1634-
- rateType
16351629
- skills
16361630
- status
16371631
- createdAt
@@ -1719,14 +1713,8 @@ components:
17191713
JobRequestBody:
17201714
required:
17211715
- projectId
1722-
- externalId
1723-
- description
17241716
- title
1725-
- startDate
1726-
- endDate
17271717
- numPositions
1728-
- resourceType
1729-
- rateType
17301718
- skills
17311719
properties:
17321720
projectId:
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/*
2+
* Make Job fields externalId, description, startDate, endDate, resourceType, rateType and workload optional.
3+
*/
4+
5+
const targetFields = [
6+
'external_id',
7+
'description',
8+
'start_date',
9+
'end_date',
10+
'resource_type',
11+
'rate_type',
12+
'workload'
13+
]
14+
15+
module.exports = {
16+
up: queryInterface => {
17+
return Promise.all(targetFields.map(field =>
18+
queryInterface.sequelize.query(`ALTER TABLE bookings.jobs ALTER COLUMN ${field} DROP NOT NULL`)
19+
))
20+
},
21+
down: queryInterface => {
22+
return Promise.all(targetFields.map(field =>
23+
queryInterface.sequelize.query(`ALTER TABLE bookings.jobs ALTER COLUMN ${field} SET NOT NULL`)
24+
))
25+
}
26+
}

src/models/Job.js

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -66,26 +66,22 @@ module.exports = (sequelize) => {
6666
},
6767
externalId: {
6868
field: 'external_id',
69-
type: Sequelize.STRING,
70-
allowNull: false
69+
type: Sequelize.STRING
7170
},
7271
description: {
73-
type: Sequelize.STRING,
74-
allowNull: false
72+
type: Sequelize.STRING
7573
},
7674
title: {
7775
type: Sequelize.STRING,
7876
allowNull: false
7977
},
8078
startDate: {
8179
field: 'start_date',
82-
type: Sequelize.DATE,
83-
allowNull: false
80+
type: Sequelize.DATE
8481
},
8582
endDate: {
8683
field: 'end_date',
87-
type: Sequelize.DATE,
88-
allowNull: false
84+
type: Sequelize.DATE
8985
},
9086
numPositions: {
9187
field: 'num_positions',
@@ -94,18 +90,15 @@ module.exports = (sequelize) => {
9490
},
9591
resourceType: {
9692
field: 'resource_type',
97-
type: Sequelize.STRING,
98-
allowNull: false
93+
type: Sequelize.STRING
9994
},
10095
rateType: {
10196
field: 'rate_type',
102-
type: Sequelize.STRING,
103-
allowNull: false
97+
type: Sequelize.STRING
10498
},
10599
workload: {
106100
field: 'workload',
107-
type: Sequelize.STRING,
108-
allowNull: false
101+
type: Sequelize.STRING
109102
},
110103
skills: {
111104
type: Sequelize.JSONB,

src/services/JobService.js

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -163,15 +163,15 @@ createJob.schema = Joi.object().keys({
163163
currentUser: Joi.object().required(),
164164
job: Joi.object().keys({
165165
projectId: Joi.number().integer().required(),
166-
externalId: Joi.string().required(),
167-
description: Joi.string().required(),
166+
externalId: Joi.string(),
167+
description: Joi.string(),
168168
title: Joi.title().required(),
169-
startDate: Joi.date().required(),
170-
endDate: Joi.date().required(),
169+
startDate: Joi.date(),
170+
endDate: Joi.date(),
171171
numPositions: Joi.number().integer().min(1).required(),
172-
resourceType: Joi.string().required(),
172+
resourceType: Joi.string(),
173173
rateType: Joi.rateType(),
174-
workload: Joi.workload().default('full-time'),
174+
workload: Joi.workload(),
175175
skills: Joi.array().items(Joi.string().uuid()).required()
176176
}).required()
177177
}).required()
@@ -253,15 +253,15 @@ fullyUpdateJob.schema = Joi.object().keys({
253253
id: Joi.string().guid().required(),
254254
data: Joi.object().keys({
255255
projectId: Joi.number().integer().required(),
256-
externalId: Joi.string().required(),
257-
description: Joi.string().required(),
256+
externalId: Joi.string(),
257+
description: Joi.string(),
258258
title: Joi.title().required(),
259-
startDate: Joi.date().required(),
260-
endDate: Joi.date().required(),
259+
startDate: Joi.date(),
260+
endDate: Joi.date(),
261261
numPositions: Joi.number().integer().min(1).required(),
262-
resourceType: Joi.string().required(),
263-
rateType: Joi.rateType().required(),
264-
workload: Joi.workload().required(),
262+
resourceType: Joi.string(),
263+
rateType: Joi.rateType(),
264+
workload: Joi.workload(),
265265
skills: Joi.array().items(Joi.string().uuid()).required(),
266266
status: Joi.jobStatus()
267267
}).required()

0 commit comments

Comments
 (0)