-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Address issues from beta testing (#34)
* Update writeup and some code * Remove React ESLint plugin from backend * Update writeup * Add note about navigation * Adjust icon size * Run `npm audit fix`
- Loading branch information
Showing
15 changed files
with
256 additions
and
163 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,56 @@ | ||
import { body } from "express-validator"; | ||
|
||
// establishes a set of rules that the body of the post route must follow | ||
export const createTask = [ | ||
// more info about validators: | ||
// https://express-validator.github.io/docs/guides/validation-chain | ||
// https://github.com/validatorjs/validator.js#validators | ||
|
||
const makeIDValidator = () => | ||
body("_id") | ||
.exists() | ||
.withMessage("_id is required") | ||
.bail() | ||
.isMongoId() | ||
.withMessage("_id must be a MongoDB object ID"); | ||
const makeTitleValidator = () => | ||
body("title") | ||
// title must exist, if not this message will be displayed | ||
.exists() | ||
.withMessage("A title is required.") | ||
.withMessage("title is required") | ||
// bail prevents the remainder of the validation chain for this field from being executed if | ||
// there was an error | ||
.bail() | ||
.notEmpty() | ||
.withMessage("title cannot be empty.") | ||
.bail() | ||
.isString() | ||
.withMessage("title must be a string.") | ||
// escape replaces potentially-dangerous characters with HTML entities | ||
.escape(), | ||
.withMessage("title must be a string") | ||
.bail() | ||
.notEmpty() | ||
.withMessage("title cannot be empty"); | ||
const makeDescriptionValidator = () => | ||
body("description") | ||
// order matters for the validation chain, by marking this field as optional, the subsequent | ||
// parts of the chain will only be evaluated if it exists | ||
// order matters for the validation chain - by marking this field as optional, the rest of | ||
// the chain will only be evaluated if it exists | ||
.optional() | ||
.escape() | ||
.isString() | ||
.withMessage("description must be a string."), | ||
body("isChecked").optional().isBoolean().withMessage("isChecked must be a boolean."), | ||
.withMessage("description must be a string"); | ||
const makeIsCheckedValidator = () => | ||
body("isChecked").optional().isBoolean().withMessage("isChecked must be a boolean"); | ||
const makeDateCreatedValidator = () => | ||
body("dateCreated").isISO8601().withMessage("dateCreated must be a valid date-time string"); | ||
// assignee is for Part 2.1 | ||
const makeAssigneeValidator = () => | ||
body("assignee").optional().isMongoId().withMessage("assignee must be a MongoDB object ID"); | ||
|
||
// establishes a set of rules that the body of the task creation route must follow | ||
export const createTask = [ | ||
makeTitleValidator(), | ||
makeDescriptionValidator(), | ||
makeIsCheckedValidator(), | ||
]; | ||
|
||
export const updateTask = [ | ||
makeIDValidator(), | ||
makeTitleValidator(), | ||
makeDescriptionValidator(), | ||
makeIsCheckedValidator(), | ||
makeDateCreatedValidator(), | ||
makeAssigneeValidator(), // for Part 2.1 | ||
]; |
Oops, something went wrong.