Skip to content

Commit 488c5ac

Browse files
author
Vikas Agarwal
committed
Removed in built validation and added explicit validation on startDate and endDate so that we can pass them without each other
1 parent 90d69bc commit 488c5ac

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

src/routes/phases/create.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ const addProjectPhaseValidations = {
1414
param: Joi.object().keys({
1515
name: Joi.string().required(),
1616
status: Joi.string().required(),
17-
startDate: Joi.date().max(Joi.ref('endDate')).optional(),
17+
startDate: Joi.date().optional(),
1818
endDate: Joi.date().optional(),
1919
duration: Joi.number().min(0).optional(),
2020
budget: Joi.number().min(0).optional(),
@@ -52,6 +52,11 @@ module.exports = [
5252
err.status = 404;
5353
throw err;
5454
}
55+
if (data.startDate !== null && data.endDate !== null && data.startDate > data.endDate) {
56+
const err = new Error('startDate must not be after endDate.');
57+
err.status = 400;
58+
throw err;
59+
}
5560
return models.ProjectPhase
5661
.create(data)
5762
.then((_newProjectPhase) => {

0 commit comments

Comments
 (0)