Skip to content

Commit

Permalink
Merge branch 'main' into IDVA5-582-unicorporated-whats-is-the-busines…
Browse files Browse the repository at this point in the history
…s-name
  • Loading branch information
atedros-ch committed Mar 7, 2024
2 parents 37abea1 + 531691b commit b1e9948
Show file tree
Hide file tree
Showing 11 changed files with 155 additions and 171 deletions.
63 changes: 0 additions & 63 deletions lib/utils/error_manifests/dateOfBirth.ts

This file was deleted.

19 changes: 19 additions & 0 deletions locales/cy/what-is-your-date-of-birth.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"whereDoYouLiveTitle" : "What is your date of birth? welsh",
"whereDoYouLiveHint" : "For example, 31 3 1980 welsh",
"day": "Day welsh",
"month": "Month welsh",
"year": "Year welsh",
"error-default" : "Your request contains validation errors welsh",
"error-invalid" : "Date of birth must be a real date welsh",
"error-dateInFuture" : "The date of birth must be in the past welsh",
"error-noData" : "Enter your date of birth welsh",
"error-noDayMonth" : "Date of birth must include a day and a month welsh",
"error-noDayYear" : "Date of birth must include a day and a year welsh",
"error-noMonthYear" : "Date of birth must include a month and a year welsh",
"error-noDay" : "Date of birth must include a day welsh",
"error-noYear" : "Date of birth must include a year welsh",
"error-tooOld" : "You must be less than 110 years old welsh",
"error-tooYoung" : "You must be at least 16 years old welsh",
"error-nonNumeric" : "Date of birth must only include numbers welsh"
}
19 changes: 19 additions & 0 deletions locales/en/what-is-your-date-of-birth.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"whereDoYouLiveTitle" : "What is your date of birth?",
"whereDoYouLiveHint" : "For example, 31 3 1980",
"day": "Day",
"month": "Month",
"year": "Year",
"error-default" : "Your request contains validation errors",
"error-invalid" : "Date of birth must be a real date",
"error-dateInFuture" : "The date of birth must be in the past",
"error-noData" : "Enter your date of birth",
"error-noDayMonth" : "Date of birth must include a day and a month",
"error-noDayYear" : "Date of birth must include a day and a year",
"error-noMonthYear" : "Date of birth must include a month and a year",
"error-noDay" : "Date of birth must include a day",
"error-noYear" : "Date of birth must include a year",
"error-tooOld" : "You must be less than 110 years old",
"error-tooYoung" : "You must be at least 16 years old",
"error-nonNumeric" : "Date of birth must only include numbers"
}
2 changes: 1 addition & 1 deletion src/main/config/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const BASE_SOLE_TRADER_URL = `${BASE_VIEWS_URL}/sole-trader`;
const BASE_LIMITED_TRADER_URL = `${BASE_VIEWS_URL}/limited`;
const BASE_UNINCORPORATED_URL = `${BASE_VIEWS_URL}/unincorporated`;
export const HOME = `${BASE_SOLE_TRADER_URL}/index/home`;
export const SOLE_TRADER_DOB = `${BASE_SOLE_TRADER_URL}/date-of-birth/capture-date-of-birth`;
export const SOLE_TRADER_DATE_OF_BIRTH = `${BASE_SOLE_TRADER_URL}/what-is-your-date-of-birth/what-is-your-date-of-birth`;
export const SOLE_TRADER_NAME = `${BASE_SOLE_TRADER_URL}/name/capture-name`;
export const SOLE_TRADER_ROLE = `${BASE_SOLE_TRADER_URL}/role/statement-relevant-officer`;
export const SOLE_TRADER_KICK_OUT = `${BASE_SOLE_TRADER_URL}/kick-out/stop-not-relevant-officer`;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,33 +2,42 @@ import { NextFunction, Request, Response } from "express";
import * as config from "../../../config";
import { validationResult } from "express-validator";
import { FormattedValidationErrors, formatValidationError } from "../../../validation/validation";
import { BASE_URL, SOLE_TRADER_WHAT_IS_YOUR_NAME, SOLE_TRADER_WHAT_IS_YOUR_NATIONALITY } from "../../../types/pageURL";
import { BASE_URL, SOLE_TRADER_WHAT_IS_YOUR_NAME, SOLE_TRADER_WHAT_IS_YOUR_NATIONALITY, SOLE_TRADER_DATE_OF_BIRTH } from "../../../types/pageURL";
import { selectLang, addLangToUrl, getLocalesService, getLocaleInfo } from "../../../utils/localise";
import { Session } from "@companieshouse/node-session-handler";
import { USER_DATA } from "../../../common/__utils/constants";
import { UserData } from "../../../model/UserData";

export const get = async (req: Request, res: Response, next: NextFunction) => {
const lang = selectLang(req.query.lang);
const locales = getLocalesService();
const session: Session = req.session as any as Session;
const userData : UserData = session?.getExtraData(USER_DATA)!;

res.render(config.SOLE_TRADER_DOB, {
res.render(config.SOLE_TRADER_DATE_OF_BIRTH, {
title: "What is your date of Birth?",
previousPage: BASE_URL + SOLE_TRADER_WHAT_IS_YOUR_NAME,
...getLocaleInfo(locales, lang),
previousPage: addLangToUrl(BASE_URL + SOLE_TRADER_WHAT_IS_YOUR_NAME, lang),
currentUrl: BASE_URL + SOLE_TRADER_DATE_OF_BIRTH,
firstName: userData?.firstName,
lastName: userData?.lastName
});
};

export const post = async (req: Request, res: Response, next: NextFunction) => {
const lang = selectLang(req.query.lang);
const locales = getLocalesService();
const session: Session = req.session as any as Session;
const userData : UserData = session?.getExtraData(USER_DATA)!;
try {
const errorList = validationResult(req);
if (!errorList.isEmpty()) {
const pageProperties = getPageProperties(formatValidationError(errorList.array()));
res.status(400).render(config.SOLE_TRADER_DOB, {
const pageProperties = getPageProperties(formatValidationError(errorList.array(), lang));
res.status(400).render(config.SOLE_TRADER_DATE_OF_BIRTH, {
previousPage: addLangToUrl(BASE_URL + SOLE_TRADER_WHAT_IS_YOUR_NAME, lang),
title: "What is your date of Birth?",
previousPage: BASE_URL + SOLE_TRADER_WHAT_IS_YOUR_NAME,
...getLocaleInfo(locales, lang),
currentUrl: BASE_URL + SOLE_TRADER_DATE_OF_BIRTH,
pageProperties: pageProperties,
payload: req.body,
firstName: userData?.firstName,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export const get = async (req: Request, res: Response, next: NextFunction) => {
const lang = selectLang(req.query.lang);
const locales = getLocalesService();
res.render(config.SOLE_TRADER_TYPE_OF_BUSINESS, {
previousPage: addLangToUrl(START, lang),
previousPage: addLangToUrl(BASE_URL + HOME_URL, lang),
title: "What type of business are you registering?",
...getLocaleInfo(locales, lang),
currentUrl: BASE_URL + TYPE_OF_BUSINESS,
Expand All @@ -26,7 +26,7 @@ export const post = async (req: Request, res: Response, next: NextFunction) => {
if (!errorList.isEmpty()) {
const pageProperties = getPageProperties(formatValidationError(errorList.array(), lang));
res.status(400).render(config.SOLE_TRADER_TYPE_OF_BUSINESS, {
previousPage: addLangToUrl(HOME_URL, lang),
previousPage: addLangToUrl(BASE_URL + HOME_URL, lang),
title: "What type of business are you registering?",
...getLocaleInfo(locales, lang),
currentUrl: BASE_URL + TYPE_OF_BUSINESS,
Expand Down
2 changes: 1 addition & 1 deletion src/main/routes/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {

import { correspondenceAddressManualValidator } from "../validation/correspondenceAddressManual";
import { whereDoYouLiveValidator } from "../validation/whereDoYouLive";
import { dateOfBirthValidator } from "../../../lib/validation/dateOfBirth";
import { dateOfBirthValidator } from "../validation/dateOfBirth";
import { nameValidator } from "../../../lib/validation/name";
import { correspondenceAddressAutoLookupValidator } from "../validation/correspondenceAddressAutoLookup";
import { correspondenceAddressListValidator } from "../validation/correspondanceAddressList";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { body } from "express-validator";
import dateOfBirthErrorManifest from "../utils/error_manifests/dateOfBirth";

export const dateOfBirthValidator = [
body("dob-day").custom((value, { req }) => dateDayChecker(req.body["dob-day"], req.body["dob-month"], req.body["dob-year"])),
Expand All @@ -10,45 +9,45 @@ export const dateOfBirthValidator = [

export const dateDayChecker = (day: string, month: string, year: string) => {
if (day.trim() === "" && month.trim() === "" && year.trim() === "") {
throw new Error(dateOfBirthErrorManifest.validation.noData.summary);
throw new Error("noData");
} else if (day.trim() === "" && month.trim() === "") {
throw new Error(dateOfBirthErrorManifest.validation.noDayMonth.summary);
throw new Error("noDayMonth");
} else if (day.trim() === "" && year.trim() === "") {
throw new Error(dateOfBirthErrorManifest.validation.noDayYear.summary);
throw new Error("noDayYear");
} else if (day.trim() === "") {
throw new Error(dateOfBirthErrorManifest.validation.noDay.summary);
throw new Error("noDay");
}
return true;
};

export const dateMonthChecker = (day: string, month: string, year: string) => {
if (day.trim() !== "" && month.trim() === "" && year.trim() === "") {
throw new Error(dateOfBirthErrorManifest.validation.noMonthYear.summary);
throw new Error("noMonthYear");
} else if (day.trim() !== "" && month.trim() === "") {
throw new Error(dateOfBirthErrorManifest.validation.noMonth.summary);
throw new Error("noMonth");
}
return true;
};

export const dateYearChecker = (day: string, month: string, year: string) => {
if (day.trim() !== "" && month.trim() !== "" && year.trim() === "") {
throw new Error(dateOfBirthErrorManifest.validation.noYear.summary);
throw new Error("noYear");
}
return true;
};

export const validDataChecker = (day: string, month: string, year: string) => {
if (day !== "" && month !== "" && year !== "") {
if (!isNumeric(day) || !isNumeric(month) || !isNumeric(year)) {
throw new Error(dateOfBirthErrorManifest.validation.nonNumeric.summary);
throw new Error("nonNumeric");
} else if (+month < 1 || +month > 12 || +year < 1000 || +year > 9999 || !isValidDay(+day, +month, +year) || day.length > 2 || month.length > 2) {
throw new Error(dateOfBirthErrorManifest.validation.invalid.summary);
throw new Error("invalid");
} else if (!isNotInFuture(+day, +month, +year)) {
throw new Error(dateOfBirthErrorManifest.validation.dateInFuture.summary);
throw new Error("dateInFuture");
} else if (!isNotTooYoung(+day, +month, +year)) {
throw new Error(dateOfBirthErrorManifest.validation.tooYoung.summary);
throw new Error("tooYoung");
} else if (!isNotTooOld(+day, +month, +year)) {
throw new Error(dateOfBirthErrorManifest.validation.tooOld.summary);
throw new Error("tooOld");
}
}
return true;
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
{% from "govuk/components/date-input/macro.njk" import govukDateInput %}
{% from "govuk/components/button/macro.njk" import govukButton %}

{% set errors = pageProperties.errors %}

{% extends "layouts/default.njk" %}

{% block main_content %}

{% if errors["dob-day"] %}
{% set errorMessageText = errors["dob-day"].text %}
{% elif errors["dob-month"] %}
{% set errorMessageText = errors["dob-month"].text %}
{% elif errors["dob-year"] %}
{% set errorMessageText = errors["dob-year"].text %}
{% endif %}

<div>
<form action="" method="POST">
{% include "partials/user_name.njk" %}

{{ govukDateInput({
id: "dob",
namePrefix: "dob",
fieldset: {
legend: {
text: i18n.whereDoYouLiveTitle,
isPageHeading: true,
classes: "govuk-fieldset__legend--l"
}
},
hint: {
text: "For example, 31 3 1980"
},
errorMessage: {
text: errorMessageText
} if errors | length,

items: [
{
name: i18n.day,
classes: "govuk-input--error govuk-input--width-2" if errors else "govuk-input--width-2",
autocomplete: "bday-day",
id: "dob-day",
value: payload["dob-day"]
},
{
name: i18n.month,
classes: "govuk-input--error govuk-input--width-2" if errors else "govuk-input--width-2",
autocomplete: "bday-month",
id: "dob-month",
value: payload["dob-month"]
},
{
name: i18n.year,
classes: "govuk-input--error govuk-input--width-4" if errors else "govuk-input--width-4",
autocomplete: "bday-year",
id: "dob-year",
value: payload["dob-year"]
}
]
}) }}

{{ govukButton({
text: i18n.Continue
}) }}
</form>
</div>

{% endblock main_content %}
Loading

0 comments on commit b1e9948

Please sign in to comment.