Skip to content
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

Address issues from beta testing #34

Merged
merged 6 commits into from
Nov 4, 2023
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
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