Skip to content

Commit

Permalink
Address issues from beta testing (#34)
Browse files Browse the repository at this point in the history
* 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
wllmwu authored Nov 4, 2023
1 parent 9d3ca9f commit 94f9704
Show file tree
Hide file tree
Showing 15 changed files with 256 additions and 163 deletions.
8 changes: 2 additions & 6 deletions backend/.eslintrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,7 @@ module.exports = {
browser: true,
es2021: true,
},
extends: [
"eslint:recommended",
"plugin:@typescript-eslint/recommended",
"plugin:react/recommended",
],
extends: ["eslint:recommended", "plugin:@typescript-eslint/recommended"],
parser: "@typescript-eslint/parser",
parserOptions: {
ecmaVersion: "latest",
Expand All @@ -16,7 +12,7 @@ module.exports = {
tsconfigRootDir: __dirname,
},
ignorePatterns: [".eslintrc.cjs"],
plugins: ["@typescript-eslint", "react", "no-relative-import-paths"],
plugins: ["@typescript-eslint", "no-relative-import-paths"],
rules: {
"default-case": "off",
"no-plusplus": "off",
Expand Down
57 changes: 43 additions & 14 deletions backend/src/validators/task.ts
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
];
Loading

0 comments on commit 94f9704

Please sign in to comment.