Skip to content

make some fields of Job optional #103

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
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
12 changes: 0 additions & 12 deletions docs/swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1624,14 +1624,8 @@ components:
required:
- id
- projectId
- externalId
- description
- title
- startDate
- endDate
- numPositions
- resourceType
- rateType
- skills
- status
- createdAt
Expand Down Expand Up @@ -1719,14 +1713,8 @@ components:
JobRequestBody:
required:
- projectId
- externalId
- description
- title
- startDate
- endDate
- numPositions
- resourceType
- rateType
- skills
properties:
projectId:
Expand Down
26 changes: 26 additions & 0 deletions migrations/2021-01-09-make-some-job-fields-optional.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/*
* Make Job fields externalId, description, startDate, endDate, resourceType, rateType and workload optional.
*/

const targetFields = [
'external_id',
'description',
'start_date',
'end_date',
'resource_type',
'rate_type',
'workload'
]

module.exports = {
up: queryInterface => {
return Promise.all(targetFields.map(field =>
queryInterface.sequelize.query(`ALTER TABLE bookings.jobs ALTER COLUMN ${field} DROP NOT NULL`)
))
},
down: queryInterface => {
return Promise.all(targetFields.map(field =>
queryInterface.sequelize.query(`ALTER TABLE bookings.jobs ALTER COLUMN ${field} SET NOT NULL`)
))
}
}
21 changes: 7 additions & 14 deletions src/models/Job.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,26 +66,22 @@ module.exports = (sequelize) => {
},
externalId: {
field: 'external_id',
type: Sequelize.STRING,
allowNull: false
type: Sequelize.STRING
},
description: {
type: Sequelize.STRING,
allowNull: false
type: Sequelize.STRING
},
title: {
type: Sequelize.STRING,
allowNull: false
},
startDate: {
field: 'start_date',
type: Sequelize.DATE,
allowNull: false
type: Sequelize.DATE
},
endDate: {
field: 'end_date',
type: Sequelize.DATE,
allowNull: false
type: Sequelize.DATE
},
numPositions: {
field: 'num_positions',
Expand All @@ -94,18 +90,15 @@ module.exports = (sequelize) => {
},
resourceType: {
field: 'resource_type',
type: Sequelize.STRING,
allowNull: false
type: Sequelize.STRING
},
rateType: {
field: 'rate_type',
type: Sequelize.STRING,
allowNull: false
type: Sequelize.STRING
},
workload: {
field: 'workload',
type: Sequelize.STRING,
allowNull: false
type: Sequelize.STRING
},
skills: {
type: Sequelize.JSONB,
Expand Down
26 changes: 13 additions & 13 deletions src/services/JobService.js
Original file line number Diff line number Diff line change
Expand Up @@ -163,15 +163,15 @@ createJob.schema = Joi.object().keys({
currentUser: Joi.object().required(),
job: Joi.object().keys({
projectId: Joi.number().integer().required(),
externalId: Joi.string().required(),
description: Joi.string().required(),
externalId: Joi.string(),
description: Joi.string(),
title: Joi.title().required(),
startDate: Joi.date().required(),
endDate: Joi.date().required(),
startDate: Joi.date(),
endDate: Joi.date(),
numPositions: Joi.number().integer().min(1).required(),
resourceType: Joi.string().required(),
resourceType: Joi.string(),
rateType: Joi.rateType(),
workload: Joi.workload().default('full-time'),
workload: Joi.workload(),
skills: Joi.array().items(Joi.string().uuid()).required()
}).required()
}).required()
Expand Down Expand Up @@ -253,15 +253,15 @@ fullyUpdateJob.schema = Joi.object().keys({
id: Joi.string().guid().required(),
data: Joi.object().keys({
projectId: Joi.number().integer().required(),
externalId: Joi.string().required(),
description: Joi.string().required(),
externalId: Joi.string(),
description: Joi.string(),
title: Joi.title().required(),
startDate: Joi.date().required(),
endDate: Joi.date().required(),
startDate: Joi.date(),
endDate: Joi.date(),
numPositions: Joi.number().integer().min(1).required(),
resourceType: Joi.string().required(),
rateType: Joi.rateType().required(),
workload: Joi.workload().required(),
resourceType: Joi.string(),
rateType: Joi.rateType(),
workload: Joi.workload(),
skills: Joi.array().items(Joi.string().uuid()).required(),
status: Joi.jobStatus()
}).required()
Expand Down