Skip to content

Commit 7baecca

Browse files
committed
fix: allow empty "description" and "resourceType"
this is done to make it easier creating UI for editing these fields, as usually forms send empty value instead of "null" or "undefined"
1 parent f93df4f commit 7baecca

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

src/bootstrap.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@ Joi.jobStatus = () => Joi.string().valid('sourcing', 'in-review', 'assigned', 'c
99
Joi.jobCandidateStatus = () => Joi.string().valid('open', 'selected', 'shortlist', 'rejected', 'cancelled')
1010
Joi.workload = () => Joi.string().valid('full-time', 'fractional')
1111
Joi.title = () => Joi.string().max(128)
12+
// Empty string is not allowed by Joi by default and must be enabled with allow('').
13+
// See https://joi.dev/api/?v=17.3.0#string fro details why it's like this.
14+
// In many cases we would like to allow empty string to make it easier to create UI for editing data.
15+
Joi.stringAllowEmpty = () => Joi.string().allow('')
1216

1317
const zapierSwitch = Joi.string().label('ZAPIER_SWITCH').valid(...Object.values(constants.Zapier.Switch))
1418

src/services/JobProcessorService.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -70,12 +70,12 @@ processCreate.schema = {
7070
id: Joi.string().uuid().required(),
7171
projectId: Joi.number().integer().required(),
7272
externalId: Joi.string(),
73-
description: Joi.string(),
73+
description: Joi.stringAllowEmpty(),
7474
title: Joi.title().required(),
7575
startDate: Joi.date(),
7676
endDate: Joi.date(),
7777
numPositions: Joi.number().integer().min(1).required(),
78-
resourceType: Joi.string(),
78+
resourceType: Joi.stringAllowEmpty(),
7979
rateType: Joi.rateType(),
8080
workload: Joi.workload(),
8181
skills: Joi.array().items(Joi.string().uuid()).required(),
@@ -119,12 +119,12 @@ processUpdate.schema = {
119119
id: Joi.string().uuid().required(),
120120
projectId: Joi.number().integer(),
121121
externalId: Joi.string(),
122-
description: Joi.string(),
122+
description: Joi.stringAllowEmpty(),
123123
title: Joi.title(),
124124
startDate: Joi.date(),
125125
endDate: Joi.date(),
126126
numPositions: Joi.number().integer().min(1),
127-
resourceType: Joi.string(),
127+
resourceType: Joi.stringAllowEmpty(),
128128
rateType: Joi.rateType(),
129129
workload: Joi.workload(),
130130
skills: Joi.array().items(Joi.string().uuid()),

0 commit comments

Comments
 (0)