diff --git a/src/routes/add-team.ts b/src/routes/add-team.ts index 5859007..19e9468 100644 --- a/src/routes/add-team.ts +++ b/src/routes/add-team.ts @@ -4,10 +4,12 @@ import { authentication } from '../middleware/authentication.middleware'; import { get, post } from '../controller/add-team.controller'; import * as config from '../config'; +import { addTeam } from '../validation/add-team.validation'; +import { checkValidations } from '../middleware/validation.middleware'; const addTeamRouter = Router(); addTeamRouter.get(config.ADD_TEAM_URL, authentication, get); -addTeamRouter.post(config.ADD_TEAM_URL, authentication, post); +addTeamRouter.post(config.ADD_TEAM_URL, authentication, ...addTeam, checkValidations, post); export default addTeamRouter; diff --git a/src/validation/add-team.validation.ts b/src/validation/add-team.validation.ts new file mode 100644 index 0000000..0ef4e55 --- /dev/null +++ b/src/validation/add-team.validation.ts @@ -0,0 +1,10 @@ +import { body } from 'express-validator'; + +import { ErrorMessages } from './error.messages'; +import { descriptionValidation } from './fields/description.validation'; + +export const addTeam = [ + body('team_name').notEmpty({ ignore_whitespace: true }).withMessage(ErrorMessages.TEAM_NAME), + body('team_maintainer_github_handle').not().isEmpty({ ignore_whitespace: true }).withMessage(ErrorMessages.TEAM_MAINTAINER_GITHUB_HANDLE), + ...descriptionValidation +]; diff --git a/src/validation/error.messages.ts b/src/validation/error.messages.ts index 6182f47..021a48d 100644 --- a/src/validation/error.messages.ts +++ b/src/validation/error.messages.ts @@ -8,5 +8,7 @@ export enum ErrorMessages { CONTRACTOR_DATE= 'Enter the GitHub account holders contract start date in the correct format', CONTRACTOR_DATE_TIME= 'The contract start date cannot be more than one year in the future', REPO_NAME = 'Enter the repository name', - VISIBILITY = 'Select a visibility option' + VISIBILITY = 'Select a visibility option', + TEAM_MAINTAINER_GITHUB_HANDLE = 'Enter the team maintainer GitHub handle', + TEAM_NAME = 'Enter the team name', } diff --git a/src/views/add-team.html b/src/views/add-team.html index 5247ff6..d85a583 100644 --- a/src/views/add-team.html +++ b/src/views/add-team.html @@ -1,10 +1,7 @@ {% extends "layout.html" %} {% block beforeContent %} - {{ govukBackLink({ - text: "Back", - href: "/landing-page" - }) }} + {% include "include/back-link.html" %} {% endblock %} {% block content %} @@ -16,46 +13,53 @@