From 187a395b84a5d12a6d33158fa9e0dc50d59edc5a Mon Sep 17 00:00:00 2001 From: hemerem-ch Date: Tue, 26 Mar 2024 07:59:42 +0000 Subject: [PATCH 01/14] - fix address bug --- .../sole-trader/correspondenceAddressConfirmController.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/controllers/features/sole-trader/correspondenceAddressConfirmController.ts b/src/main/controllers/features/sole-trader/correspondenceAddressConfirmController.ts index e1e40d74..6747b293 100644 --- a/src/main/controllers/features/sole-trader/correspondenceAddressConfirmController.ts +++ b/src/main/controllers/features/sole-trader/correspondenceAddressConfirmController.ts @@ -12,8 +12,8 @@ export const get = async (req: Request, res: Response, next: NextFunction) => { const locales = getLocalesService(); const session: Session = req.session as any as Session; const ACSPData : ACSPData = session?.getExtraData(USER_DATA)!; - const { firstName, lastName, addresses } = ACSPData; + console.log(addresses); res.render(config.SOLE_TRADER_CORRESPONDENCE_ADDRESS_CONFIRM, { previousPage: addLangToUrl(BASE_URL + SOLE_TRADER_AUTO_LOOKUP_ADDRESS, lang), @@ -23,7 +23,7 @@ export const get = async (req: Request, res: Response, next: NextFunction) => { currentUrl: BASE_URL + SOLE_TRADER_CORRESPONDENCE_ADDRESS_CONFIRM, firstName, lastName, - correspondenceAddress: addresses ? [0] : "" + correspondenceAddress: addresses ? addresses[0] : "" }); }; From d6ced742d310b6ecb4d1ee42a0129f124c2d11c0 Mon Sep 17 00:00:00 2001 From: hemerem-ch Date: Tue, 26 Mar 2024 17:04:46 +0000 Subject: [PATCH 02/14] - fix address bug, added service layers --- .../correspodanceAddressDetailsController.ts | 19 +---- ...rrespondenceAddressAutoLookupController.ts | 57 +------------- .../correspondenceAddressManualController.ts | 18 +---- .../address-autolookup.ts | 76 +++++++++++++++++++ .../correspondence-address/address-details.ts | 24 ++++++ .../correspondence-address/address-manual.ts | 25 ++++++ 6 files changed, 134 insertions(+), 85 deletions(-) create mode 100644 src/main/services/correspondence-address/address-autolookup.ts create mode 100644 src/main/services/correspondence-address/address-details.ts create mode 100644 src/main/services/correspondence-address/address-manual.ts diff --git a/src/main/controllers/features/sole-trader/correspodanceAddressDetailsController.ts b/src/main/controllers/features/sole-trader/correspodanceAddressDetailsController.ts index 543eda33..44a648a6 100644 --- a/src/main/controllers/features/sole-trader/correspodanceAddressDetailsController.ts +++ b/src/main/controllers/features/sole-trader/correspodanceAddressDetailsController.ts @@ -8,6 +8,7 @@ import { ACSPData } from "../../../model/ACSPData"; import { Session } from "@companieshouse/node-session-handler"; import { CORRESPONDENCE_ADDRESS, USER_DATA } from "../../../common/__utils/constants"; import { saveDataInSession } from "../../../common/__utils/sessionHelper"; +import { CorrespondenceAddressDetailsService } from "../../../services/correspondence-address/address-details"; export const get = async (req: Request, res: Response, next: NextFunction) => { const session: Session = req.session as any as Session; @@ -49,24 +50,8 @@ export const post = async (req: Request, res: Response, next: NextFunction) => { addresses: ACSPData?.addresses }); } else { - const addressList = ACSPData.addresses!; const selectPremise = req.body.correspondenceAddress; - for (const ukAddress of addressList) { - if (ukAddress.propertyDetails!.toUpperCase() === selectPremise.toUpperCase()) { - // Save the correspondence address to session - const correspondenceAddress = { - propertyDetails: ukAddress.propertyDetails, - line1: ukAddress.line1, - line2: ukAddress.line2, - town: ukAddress.town, - country: ukAddress.country, - postcode: ukAddress.postcode - }; - saveDataInSession(req, CORRESPONDENCE_ADDRESS, correspondenceAddress); - - } - - } + CorrespondenceAddressDetailsService.saveCorrespondenceDetailsAddress(req, ACSPData, selectPremise); const nextPageUrl = addLangToUrl(BASE_URL + SOLE_TRADER_CORRESPONDENCE_ADDRESS_CONFIRM, lang); res.redirect(nextPageUrl); } diff --git a/src/main/controllers/features/sole-trader/correspondenceAddressAutoLookupController.ts b/src/main/controllers/features/sole-trader/correspondenceAddressAutoLookupController.ts index 5fc0278e..269cf304 100644 --- a/src/main/controllers/features/sole-trader/correspondenceAddressAutoLookupController.ts +++ b/src/main/controllers/features/sole-trader/correspondenceAddressAutoLookupController.ts @@ -13,6 +13,7 @@ import { ACSPData } from "../../../model/ACSPData"; import { Session } from "@companieshouse/node-session-handler"; import { USER_DATA } from "../../../common/__utils/constants"; import { saveDataInSession } from "../../../common/__utils/sessionHelper"; +import CorrespondenceAddressAutoLookService from "../../../services/correspondence-address/address-autolookup"; export const get = async (req: Request, res: Response, next: NextFunction) => { const session: Session = req.session as any as Session; @@ -60,60 +61,10 @@ export const post = async (req: Request, res: Response, next: NextFunction) => { const correspondencePremise = req.body.premise; if (correspondencePremise !== "" && ukAddresses.find((address) => address.premise === correspondencePremise)) { - let address = { - premise: "", - addressLine1: "", - addressLine2: "", - postTown: "", - postalCode: "", - country: "" - }; - for (const ukAddress of ukAddresses) { - if (ukAddress.premise === correspondencePremise) { - address = { - premise: ukAddress.premise, - addressLine1: ukAddress.addressLine1, - addressLine2: ukAddress.addressLine2!, - postTown: ukAddress.postTown, - postalCode: ukAddress.postcode, - country: getCountryFromKey(ukAddress.country) - }; - } - } - // Save the correspondence address to session - const correspondenceAddress : Address = { - propertyDetails: address.premise, - line1: address.addressLine1, - line2: address.addressLine2, - town: address.postTown, - country: address.country, - postcode: address.postalCode - }; - const userAddresses : Array
= ACSPData?.addresses ? ACSPData.addresses : []; - userAddresses.push(correspondenceAddress); - ACSPData.addresses = userAddresses; - saveDataInSession(req, USER_DATA, ACSPData); - res.redirect(BASE_URL + SOLE_TRADER_CORRESPONDENCE_ADDRESS_CONFIRM); - + CorrespondenceAddressAutoLookService.saveCorrespondenceAddressToSession(session, req, ukAddresses, correspondencePremise); + res.redirect(addLangToUrl(BASE_URL + SOLE_TRADER_CORRESPONDENCE_ADDRESS_CONFIRM, lang)); } else { - - const addressList : Array
= []; - for (const ukAddress of ukAddresses) { - const address = { - propertyDetails: ukAddress.premise, - line1: ukAddress.addressLine1, - line2: ukAddress.addressLine2, - town: ukAddress.postTown, - country: getCountryFromKey(ukAddress.country), - postcode: ukAddress.postcode, - formattedAddress: ukAddress.premise + ", " + ukAddress.addressLine1 + ", " + ukAddress.postTown + ", " + getCountryFromKey(ukAddress.country) + ", " + ukAddress.postcode - }; - - addressList.push(address); - - } - ACSPData.addresses = addressList; - saveDataInSession(req, USER_DATA, ACSPData); + CorrespondenceAddressAutoLookService.saveAddressListToSession(session, req, ukAddresses); const nextPageUrl = addLangToUrl(BASE_URL + SOLE_TRADER_AUTO_LOOKUP_ADDRESS_LIST, lang); res.redirect(nextPageUrl); diff --git a/src/main/controllers/features/sole-trader/correspondenceAddressManualController.ts b/src/main/controllers/features/sole-trader/correspondenceAddressManualController.ts index f3930908..bd31134e 100644 --- a/src/main/controllers/features/sole-trader/correspondenceAddressManualController.ts +++ b/src/main/controllers/features/sole-trader/correspondenceAddressManualController.ts @@ -9,6 +9,7 @@ import { ACSPData } from "../../../model/ACSPData"; import { Session } from "@companieshouse/node-session-handler"; import { USER_DATA } from "../../../common/__utils/constants"; import { saveDataInSession } from "../../../common/__utils/sessionHelper"; +import { CorrespondenceAddressManualService } from "../../../services/correspondence-address/address-manual"; export const get = async (req: Request, res: Response, next: NextFunction) => { const lang = selectLang(req.query.lang); @@ -46,21 +47,8 @@ export const post = async (req: Request, res: Response, next: NextFunction) => { lastName: ACSPData?.lastName }); } else { - // Save the correspondence address to session - const correspondenceAddress : Address = { - propertyDetails: req.body.addressPropertyDetails, - line1: req.body.addressLine1, - line2: req.body.addressLine2, - town: req.body.addressTown, - county: req.body.addressCounty, - country: req.body.addressCountry, - postcode: req.body.addressPostcode - }; - const userAddress : Array
= ACSPData?.addresses ? ACSPData.addresses : []; - userAddress.push(correspondenceAddress); - ACSPData.addresses = userAddress; - saveDataInSession(req, USER_DATA, ACSPData); - res.redirect(BASE_URL + SOLE_TRADER_CORRESPONDENCE_ADDRESS_CONFIRM); + CorrespondenceAddressManualService.saveCorrespondenceManualAddress(req, ACSPData); + res.redirect(addLangToUrl(BASE_URL + SOLE_TRADER_CORRESPONDENCE_ADDRESS_CONFIRM, lang)); } } catch (error) { next(error); diff --git a/src/main/services/correspondence-address/address-autolookup.ts b/src/main/services/correspondence-address/address-autolookup.ts new file mode 100644 index 00000000..471710d5 --- /dev/null +++ b/src/main/services/correspondence-address/address-autolookup.ts @@ -0,0 +1,76 @@ +import { Request } from "express"; +import { Address } from "../../model/Address"; +import { ACSPData } from "../../model/ACSPData"; +import { Session } from "@companieshouse/node-session-handler"; +import { USER_DATA } from "../../common/__utils/constants"; +import { saveDataInSession } from "../../common/__utils/sessionHelper"; +import { getCountryFromKey } from "../../utils/web"; +import { UKAddress } from "@companieshouse/api-sdk-node/dist/services/postcode-lookup"; + +class CorrespondenceAddressAutoLookService { + static saveCorrespondenceAddressToSession ( + session: Session, + req: Request, + ukAddresses: UKAddress[], + correspondencePremise: string + ): void { + const ACSPData: ACSPData = session?.getExtraData(USER_DATA)!; + + let address = { + premise: "", + addressLine1: "", + addressLine2: "", + postTown: "", + postalCode: "", + country: "" + }; + for (const ukAddress of ukAddresses) { + if (ukAddress.premise === correspondencePremise) { + address = { + premise: ukAddress.premise, + addressLine1: ukAddress.addressLine1, + addressLine2: ukAddress.addressLine2!, + postTown: ukAddress.postTown, + postalCode: ukAddress.postcode, + country: getCountryFromKey(ukAddress.country) + }; + } + } + + const correspondenceAddress: Address = { + propertyDetails: address.premise, + line1: address.addressLine1, + line2: address.addressLine2, + town: address.postTown, + country: address.country, + postcode: address.postalCode + }; + const userAddresses: Array
= ACSPData?.addresses ? ACSPData.addresses : []; + userAddresses.push(correspondenceAddress); + ACSPData.addresses = userAddresses; + saveDataInSession(req, USER_DATA, ACSPData); + } + + static saveAddressListToSession (session: Session, req: Request, ukAddresses: UKAddress[]): void { + const ACSPData: ACSPData = session?.getExtraData(USER_DATA)!; + + const addressList: Array
= []; + for (const ukAddress of ukAddresses) { + const address = { + propertyDetails: ukAddress.premise, + line1: ukAddress.addressLine1, + line2: ukAddress.addressLine2, + town: ukAddress.postTown, + country: getCountryFromKey(ukAddress.country), + postcode: ukAddress.postcode, + formattedAddress: `${ukAddress.premise}, ${ukAddress.addressLine1}, ${ukAddress.postTown}, ${getCountryFromKey(ukAddress.country)}, ${ukAddress.postcode}` + }; + addressList.push(address); + } + + ACSPData.addresses = addressList; + saveDataInSession(req, USER_DATA, ACSPData); + } +} + +export default CorrespondenceAddressAutoLookService; diff --git a/src/main/services/correspondence-address/address-details.ts b/src/main/services/correspondence-address/address-details.ts new file mode 100644 index 00000000..c94eef0a --- /dev/null +++ b/src/main/services/correspondence-address/address-details.ts @@ -0,0 +1,24 @@ +import { Request } from "express"; +import { saveDataInSession } from "../../common/__utils/sessionHelper"; +import { ACSPData } from "../../model/ACSPData"; +import { CORRESPONDENCE_ADDRESS } from "../../common/__utils/constants"; + +export class CorrespondenceAddressDetailsService { + static saveCorrespondenceDetailsAddress (req: Request, ACSPData: ACSPData, selectPremise: string): void { + const addressList = ACSPData.addresses!; + for (const ukAddress of addressList) { + if (ukAddress.propertyDetails!.toUpperCase() === selectPremise.toUpperCase()) { + const correspondenceAddress = { + propertyDetails: ukAddress.propertyDetails, + line1: ukAddress.line1, + line2: ukAddress.line2, + town: ukAddress.town, + country: ukAddress.country, + postcode: ukAddress.postcode + }; + saveDataInSession(req, CORRESPONDENCE_ADDRESS, correspondenceAddress); + break; + } + } + } +} diff --git a/src/main/services/correspondence-address/address-manual.ts b/src/main/services/correspondence-address/address-manual.ts new file mode 100644 index 00000000..61e8d95a --- /dev/null +++ b/src/main/services/correspondence-address/address-manual.ts @@ -0,0 +1,25 @@ +import { Request } from "express"; +import { Address } from "../../model/Address"; +import { ACSPData } from "../../model/ACSPData"; +import { saveDataInSession } from "../../common/__utils/sessionHelper"; +import { USER_DATA } from "../../common/__utils/constants"; + +export class CorrespondenceAddressManualService { + static saveCorrespondenceManualAddress (req: Request, ACSPData: ACSPData): void { + const correspondenceAddress: Address = { + propertyDetails: req.body.addressPropertyDetails, + line1: req.body.addressLine1, + line2: req.body.addressLine2, + town: req.body.addressTown, + county: req.body.addressCounty, + country: req.body.addressCountry, + postcode: req.body.addressPostcode + }; + + const userAddress: Array
= ACSPData?.addresses ? ACSPData.addresses : []; + userAddress.push(correspondenceAddress); + ACSPData.addresses = userAddress; + + saveDataInSession(req, USER_DATA, ACSPData); + } +} From f96e60d4be9a691c8746f9bd7f72c18dc86ba198 Mon Sep 17 00:00:00 2001 From: hemerem-ch Date: Tue, 26 Mar 2024 19:03:00 +0000 Subject: [PATCH 03/14] - fix address bug, added service layers --- .../correspodanceAddressDetailsController.ts | 5 +- ...rrespondenceAddressAutoLookupController.ts | 71 ++---------------- .../correspondenceAddressConfirmController.ts | 5 +- .../correspondenceAddressManualController.ts | 18 +---- .../address-autolookup.ts | 72 ++++++++++--------- .../correspondence-address/address-details.ts | 4 +- .../correspondence-address/address-manual.ts | 9 ++- 7 files changed, 55 insertions(+), 129 deletions(-) diff --git a/src/main/controllers/features/sole-trader/correspodanceAddressDetailsController.ts b/src/main/controllers/features/sole-trader/correspodanceAddressDetailsController.ts index 6e685e09..ec251942 100644 --- a/src/main/controllers/features/sole-trader/correspodanceAddressDetailsController.ts +++ b/src/main/controllers/features/sole-trader/correspodanceAddressDetailsController.ts @@ -51,11 +51,8 @@ export const post = async (req: Request, res: Response, next: NextFunction) => { }); } else { - - /*const addressList = acspData.addresses!;*/ - const selectPremise = req.body.correspondenceAddress; - CorrespondenceAddressDetailsService.saveCorrespondenceDetailsAddress(req, ACSPData, selectPremise); + CorrespondenceAddressDetailsService.saveCorrespondenceDetailsAddress(req, acspData, selectPremise); const nextPageUrl = addLangToUrl(BASE_URL + SOLE_TRADER_CORRESPONDENCE_ADDRESS_CONFIRM, lang); res.redirect(nextPageUrl); } diff --git a/src/main/controllers/features/sole-trader/correspondenceAddressAutoLookupController.ts b/src/main/controllers/features/sole-trader/correspondenceAddressAutoLookupController.ts index 0b5371b8..b7935fe6 100644 --- a/src/main/controllers/features/sole-trader/correspondenceAddressAutoLookupController.ts +++ b/src/main/controllers/features/sole-trader/correspondenceAddressAutoLookupController.ts @@ -1,3 +1,4 @@ + import { NextFunction, Request, Response } from "express"; import { ValidationError, validationResult } from "express-validator"; import { FormattedValidationErrors, formatValidationError } from "../../../validation/validation"; @@ -55,75 +56,17 @@ export const post = async (req: Request, res: Response, next: NextFunction) => { } else { const postcode = req.body.postCode; const correspondencePremise = req.body.premise; - - - if (correspondencePremise !== "" && ukAddresses.find((address) => address.premise === correspondencePremise)) { - CorrespondenceAddressAutoLookService.saveCorrespondenceAddressToSession(session, req, ukAddresses, correspondencePremise); - res.redirect(addLangToUrl(BASE_URL + SOLE_TRADER_CORRESPONDENCE_ADDRESS_CONFIRM, lang)); - } else { - CorrespondenceAddressAutoLookService.saveAddressListToSession(session, req, ukAddresses); - const nextPageUrl = addLangToUrl(BASE_URL + SOLE_TRADER_AUTO_LOOKUP_ADDRESS_LIST, lang); - res.redirect(nextPageUrl); - - /* getAddressFromPostcode(postcode).then((ukAddresses) => { + getAddressFromPostcode(postcode).then((ukAddresses) => { if (correspondencePremise !== "" && ukAddresses.find((address) => address.premise === correspondencePremise)) { - let address = { - premise: "", - addressLine1: "", - addressLine2: "", - postTown: "", - postalCode: "", - country: "" - }; - for (const ukAddress of ukAddresses) { - if (ukAddress.premise === correspondencePremise) { - address = { - premise: ukAddress.premise, - addressLine1: ukAddress.addressLine1, - addressLine2: ukAddress.addressLine2!, - postTown: ukAddress.postTown, - postalCode: ukAddress.postcode, - country: getCountryFromKey(ukAddress.country) - }; - } - } - // Save the correspondence address to session - const correspondenceAddress : Address = { - propertyDetails: address.premise, - line1: address.addressLine1, - line2: address.addressLine2, - town: address.postTown, - country: address.country, - postcode: address.postalCode - }; - const userAddresses : Array
= acspData?.addresses ? acspData.addresses : []; - userAddresses.push(correspondenceAddress); - acspData.addresses = userAddresses; - saveDataInSession(req, USER_DATA, acspData); - res.redirect(BASE_URL + SOLE_TRADER_CORRESPONDENCE_ADDRESS_CONFIRM); - } else { - - const addressList : Array
= []; - for (const ukAddress of ukAddresses) { - const address = { - propertyDetails: ukAddress.premise, - line1: ukAddress.addressLine1, - line2: ukAddress.addressLine2, - town: ukAddress.postTown, - country: getCountryFromKey(ukAddress.country), - postcode: ukAddress.postcode, - formattedAddress: ukAddress.premise + ", " + ukAddress.addressLine1 + ", " + ukAddress.postTown + ", " + getCountryFromKey(ukAddress.country) + ", " + ukAddress.postcode - }; + CorrespondenceAddressAutoLookService.saveCorrespondenceAddressToSession(session, req, ukAddresses, correspondencePremise); + res.redirect(addLangToUrl(BASE_URL + SOLE_TRADER_CORRESPONDENCE_ADDRESS_CONFIRM, lang)); - addressList.push(address); + } else { - } - acspData.addresses = addressList; - saveDataInSession(req, USER_DATA, acspData); + CorrespondenceAddressAutoLookService.saveAddressListToSession(session, req, ukAddresses); const nextPageUrl = addLangToUrl(BASE_URL + SOLE_TRADER_AUTO_LOOKUP_ADDRESS_LIST, lang); - res.redirect(nextPageUrl);*/ - + res.redirect(nextPageUrl); } diff --git a/src/main/controllers/features/sole-trader/correspondenceAddressConfirmController.ts b/src/main/controllers/features/sole-trader/correspondenceAddressConfirmController.ts index 0adb26a5..85f4e884 100644 --- a/src/main/controllers/features/sole-trader/correspondenceAddressConfirmController.ts +++ b/src/main/controllers/features/sole-trader/correspondenceAddressConfirmController.ts @@ -14,10 +14,9 @@ export const get = async (req: Request, res: Response, next: NextFunction) => { const acspData : ACSPData = session?.getExtraData(USER_DATA)!; const { firstName, lastName, addresses } = acspData; -/* const acspData : ACSPData = session?.getExtraData(USER_DATA)!; - - const { firstName, lastName, addresses } = acspData;*/ + /* const acspData : ACSPData = session?.getExtraData(USER_DATA)!; + const { firstName, lastName, addresses } = acspData; */ res.render(config.SOLE_TRADER_CORRESPONDENCE_ADDRESS_CONFIRM, { previousPage: addLangToUrl(BASE_URL + SOLE_TRADER_AUTO_LOOKUP_ADDRESS, lang), diff --git a/src/main/controllers/features/sole-trader/correspondenceAddressManualController.ts b/src/main/controllers/features/sole-trader/correspondenceAddressManualController.ts index 7f05db4b..ca51e667 100644 --- a/src/main/controllers/features/sole-trader/correspondenceAddressManualController.ts +++ b/src/main/controllers/features/sole-trader/correspondenceAddressManualController.ts @@ -48,25 +48,9 @@ export const post = async (req: Request, res: Response, next: NextFunction) => { }); } else { - CorrespondenceAddressManualService.saveCorrespondenceManualAddress(req, ACSPData); + CorrespondenceAddressManualService.saveCorrespondenceManualAddress(req, acspData); res.redirect(addLangToUrl(BASE_URL + SOLE_TRADER_CORRESPONDENCE_ADDRESS_CONFIRM, lang)); - // Save the correspondence address to session - /*const correspondenceAddress : Address = { - propertyDetails: req.body.addressPropertyDetails, - line1: req.body.addressLine1, - line2: req.body.addressLine2, - town: req.body.addressTown, - county: req.body.addressCounty, - country: req.body.addressCountry, - postcode: req.body.addressPostcode - }; - const userAddress : Array
= acspData?.addresses ? acspData.addresses : []; - userAddress.push(correspondenceAddress); - acspData.addresses = userAddress; - saveDataInSession(req, USER_DATA, acspData); - res.redirect(BASE_URL + SOLE_TRADER_CORRESPONDENCE_ADDRESS_CONFIRM);*/ - } } catch (error) { next(error); diff --git a/src/main/services/correspondence-address/address-autolookup.ts b/src/main/services/correspondence-address/address-autolookup.ts index 471710d5..84198082 100644 --- a/src/main/services/correspondence-address/address-autolookup.ts +++ b/src/main/services/correspondence-address/address-autolookup.ts @@ -1,57 +1,59 @@ -import { Request } from "express"; -import { Address } from "../../model/Address"; -import { ACSPData } from "../../model/ACSPData"; +import { UKAddress } from "@companieshouse/api-sdk-node/dist/services/postcode-lookup/types"; import { Session } from "@companieshouse/node-session-handler"; -import { USER_DATA } from "../../common/__utils/constants"; +import { Request } from "express"; +import { ADDRESS_LIST, USER_DATA } from "../../common/__utils/constants"; import { saveDataInSession } from "../../common/__utils/sessionHelper"; +import { ACSPData } from "../../model/ACSPData"; +import { Address } from "../../model/Address"; +import { Company } from "../../model/Company"; import { getCountryFromKey } from "../../utils/web"; -import { UKAddress } from "@companieshouse/api-sdk-node/dist/services/postcode-lookup"; -class CorrespondenceAddressAutoLookService { - static saveCorrespondenceAddressToSession ( - session: Session, - req: Request, - ukAddresses: UKAddress[], - correspondencePremise: string - ): void { - const ACSPData: ACSPData = session?.getExtraData(USER_DATA)!; +export class CorrespondenceAddressAutoLookService { + static saveAddressListToSession (session: Session, req: Request>, ukAddresses: UKAddress[]) { + throw new Error("Method not implemented."); + } + + static saveCorrespondenceAddressToSession (session: Session, req: Request, ukAddresses: UKAddress[], inputPremise: string): void { + const acspData: ACSPData = session?.getExtraData(USER_DATA)!; let address = { premise: "", - addressLine1: "", - addressLine2: "", - postTown: "", - postalCode: "", - country: "" + propertyDetails: "", + line1: "", + line2: "", + town: "", + country: "", + postcode: "" }; for (const ukAddress of ukAddresses) { - if (ukAddress.premise === correspondencePremise) { + if (ukAddress.premise === inputPremise) { address = { + propertyDetails: ukAddress.premise, premise: ukAddress.premise, - addressLine1: ukAddress.addressLine1, - addressLine2: ukAddress.addressLine2!, - postTown: ukAddress.postTown, - postalCode: ukAddress.postcode, - country: getCountryFromKey(ukAddress.country) + line1: ukAddress.addressLine1, + line2: ukAddress.addressLine2!, + town: ukAddress.postTown, + country: getCountryFromKey(ukAddress.country), + postcode: ukAddress.postcode }; } } const correspondenceAddress: Address = { propertyDetails: address.premise, - line1: address.addressLine1, - line2: address.addressLine2, - town: address.postTown, + line1: address.line1, + line2: address.line2, + town: address.town, country: address.country, - postcode: address.postalCode + postcode: address.postcode }; - const userAddresses: Array
= ACSPData?.addresses ? ACSPData.addresses : []; + const userAddresses: Array
= acspData?.addresses ? acspData.addresses : []; userAddresses.push(correspondenceAddress); - ACSPData.addresses = userAddresses; - saveDataInSession(req, USER_DATA, ACSPData); + acspData.addresses = userAddresses; + saveDataInSession(req, USER_DATA, acspData); } - static saveAddressListToSession (session: Session, req: Request, ukAddresses: UKAddress[]): void { + public saveAddressListToSession (session: Session, req: Request, ukAddresses: UKAddress[]): void { const ACSPData: ACSPData = session?.getExtraData(USER_DATA)!; const addressList: Array
= []; @@ -65,11 +67,13 @@ class CorrespondenceAddressAutoLookService { postcode: ukAddress.postcode, formattedAddress: `${ukAddress.premise}, ${ukAddress.addressLine1}, ${ukAddress.postTown}, ${getCountryFromKey(ukAddress.country)}, ${ukAddress.postcode}` }; + addressList.push(address); - } + } + // Save the list of addresses to the session ACSPData.addresses = addressList; - saveDataInSession(req, USER_DATA, ACSPData); + saveDataInSession(req, ADDRESS_LIST, addressList); } } diff --git a/src/main/services/correspondence-address/address-details.ts b/src/main/services/correspondence-address/address-details.ts index c94eef0a..e15c5ada 100644 --- a/src/main/services/correspondence-address/address-details.ts +++ b/src/main/services/correspondence-address/address-details.ts @@ -4,8 +4,8 @@ import { ACSPData } from "../../model/ACSPData"; import { CORRESPONDENCE_ADDRESS } from "../../common/__utils/constants"; export class CorrespondenceAddressDetailsService { - static saveCorrespondenceDetailsAddress (req: Request, ACSPData: ACSPData, selectPremise: string): void { - const addressList = ACSPData.addresses!; + static saveCorrespondenceDetailsAddress (req: Request, acspData: ACSPData, selectPremise: string): void { + const addressList = acspData.addresses!; for (const ukAddress of addressList) { if (ukAddress.propertyDetails!.toUpperCase() === selectPremise.toUpperCase()) { const correspondenceAddress = { diff --git a/src/main/services/correspondence-address/address-manual.ts b/src/main/services/correspondence-address/address-manual.ts index 61e8d95a..a8c4ff79 100644 --- a/src/main/services/correspondence-address/address-manual.ts +++ b/src/main/services/correspondence-address/address-manual.ts @@ -5,7 +5,7 @@ import { saveDataInSession } from "../../common/__utils/sessionHelper"; import { USER_DATA } from "../../common/__utils/constants"; export class CorrespondenceAddressManualService { - static saveCorrespondenceManualAddress (req: Request, ACSPData: ACSPData): void { + static saveCorrespondenceManualAddress (req: Request, acspData: ACSPData): void { const correspondenceAddress: Address = { propertyDetails: req.body.addressPropertyDetails, line1: req.body.addressLine1, @@ -16,10 +16,9 @@ export class CorrespondenceAddressManualService { postcode: req.body.addressPostcode }; - const userAddress: Array
= ACSPData?.addresses ? ACSPData.addresses : []; + const userAddress: Array
= acspData?.addresses ? acspData.addresses : []; userAddress.push(correspondenceAddress); - ACSPData.addresses = userAddress; - - saveDataInSession(req, USER_DATA, ACSPData); + acspData.addresses = userAddress; + saveDataInSession(req, USER_DATA, acspData); } } From 55c713ab0746ce68b10746e4f53cf1b7375dd9a1 Mon Sep 17 00:00:00 2001 From: hemerem-ch Date: Wed, 27 Mar 2024 13:22:19 +0000 Subject: [PATCH 04/14] changes to method parameter --- .../correspodanceAddressDetailsController.ts | 5 +++-- ...rrespondenceAddressAutoLookupController.ts | 8 ++++---- .../correspondenceAddressConfirmController.ts | 4 ---- .../correspondenceAddressManualController.ts | 4 ++-- .../address-autolookup.ts | 19 +++++++------------ .../correspondence-address/address-details.ts | 2 +- .../correspondence-address/address-manual.ts | 2 +- 7 files changed, 18 insertions(+), 26 deletions(-) diff --git a/src/main/controllers/features/sole-trader/correspodanceAddressDetailsController.ts b/src/main/controllers/features/sole-trader/correspodanceAddressDetailsController.ts index ec251942..2494ae4c 100644 --- a/src/main/controllers/features/sole-trader/correspodanceAddressDetailsController.ts +++ b/src/main/controllers/features/sole-trader/correspodanceAddressDetailsController.ts @@ -51,8 +51,9 @@ export const post = async (req: Request, res: Response, next: NextFunction) => { }); } else { - const selectPremise = req.body.correspondenceAddress; - CorrespondenceAddressDetailsService.saveCorrespondenceDetailsAddress(req, acspData, selectPremise); + const correspondenceAddress = req.body.correspondenceAddress; + const addressDetailsService = new CorrespondenceAddressDetailsService(); + addressDetailsService.saveCorrespondenceDetailsAddress(req, acspData, correspondenceAddress); const nextPageUrl = addLangToUrl(BASE_URL + SOLE_TRADER_CORRESPONDENCE_ADDRESS_CONFIRM, lang); res.redirect(nextPageUrl); } diff --git a/src/main/controllers/features/sole-trader/correspondenceAddressAutoLookupController.ts b/src/main/controllers/features/sole-trader/correspondenceAddressAutoLookupController.ts index b7935fe6..0362ed70 100644 --- a/src/main/controllers/features/sole-trader/correspondenceAddressAutoLookupController.ts +++ b/src/main/controllers/features/sole-trader/correspondenceAddressAutoLookupController.ts @@ -58,13 +58,13 @@ export const post = async (req: Request, res: Response, next: NextFunction) => { const correspondencePremise = req.body.premise; getAddressFromPostcode(postcode).then((ukAddresses) => { if (correspondencePremise !== "" && ukAddresses.find((address) => address.premise === correspondencePremise)) { - - CorrespondenceAddressAutoLookService.saveCorrespondenceAddressToSession(session, req, ukAddresses, correspondencePremise); + const autoLookupSessionservice = new CorrespondenceAddressAutoLookService(); + autoLookupSessionservice.saveCorrespondenceAddressToSession(acspData, req, ukAddresses, correspondencePremise); res.redirect(addLangToUrl(BASE_URL + SOLE_TRADER_CORRESPONDENCE_ADDRESS_CONFIRM, lang)); } else { - - CorrespondenceAddressAutoLookService.saveAddressListToSession(session, req, ukAddresses); + const autoLookupListservice = new CorrespondenceAddressAutoLookService(); + autoLookupListservice.saveAddressListToSession(acspData, req, ukAddresses); const nextPageUrl = addLangToUrl(BASE_URL + SOLE_TRADER_AUTO_LOOKUP_ADDRESS_LIST, lang); res.redirect(nextPageUrl); diff --git a/src/main/controllers/features/sole-trader/correspondenceAddressConfirmController.ts b/src/main/controllers/features/sole-trader/correspondenceAddressConfirmController.ts index 85f4e884..034bc397 100644 --- a/src/main/controllers/features/sole-trader/correspondenceAddressConfirmController.ts +++ b/src/main/controllers/features/sole-trader/correspondenceAddressConfirmController.ts @@ -14,10 +14,6 @@ export const get = async (req: Request, res: Response, next: NextFunction) => { const acspData : ACSPData = session?.getExtraData(USER_DATA)!; const { firstName, lastName, addresses } = acspData; - /* const acspData : ACSPData = session?.getExtraData(USER_DATA)!; - - const { firstName, lastName, addresses } = acspData; */ - res.render(config.SOLE_TRADER_CORRESPONDENCE_ADDRESS_CONFIRM, { previousPage: addLangToUrl(BASE_URL + SOLE_TRADER_AUTO_LOOKUP_ADDRESS, lang), editPage: addLangToUrl(BASE_URL + SOLE_TRADER_MANUAL_CORRESPONDENCE_ADDRESS, lang), diff --git a/src/main/controllers/features/sole-trader/correspondenceAddressManualController.ts b/src/main/controllers/features/sole-trader/correspondenceAddressManualController.ts index ca51e667..f7709ab3 100644 --- a/src/main/controllers/features/sole-trader/correspondenceAddressManualController.ts +++ b/src/main/controllers/features/sole-trader/correspondenceAddressManualController.ts @@ -47,8 +47,8 @@ export const post = async (req: Request, res: Response, next: NextFunction) => { lastName: acspData?.lastName }); } else { - - CorrespondenceAddressManualService.saveCorrespondenceManualAddress(req, acspData); + const AddressManualservice = new CorrespondenceAddressManualService(); + AddressManualservice.saveCorrespondenceManualAddress(req, acspData); res.redirect(addLangToUrl(BASE_URL + SOLE_TRADER_CORRESPONDENCE_ADDRESS_CONFIRM, lang)); } diff --git a/src/main/services/correspondence-address/address-autolookup.ts b/src/main/services/correspondence-address/address-autolookup.ts index 84198082..7b3ecb73 100644 --- a/src/main/services/correspondence-address/address-autolookup.ts +++ b/src/main/services/correspondence-address/address-autolookup.ts @@ -5,16 +5,10 @@ import { ADDRESS_LIST, USER_DATA } from "../../common/__utils/constants"; import { saveDataInSession } from "../../common/__utils/sessionHelper"; import { ACSPData } from "../../model/ACSPData"; import { Address } from "../../model/Address"; -import { Company } from "../../model/Company"; import { getCountryFromKey } from "../../utils/web"; export class CorrespondenceAddressAutoLookService { - static saveAddressListToSession (session: Session, req: Request>, ukAddresses: UKAddress[]) { - throw new Error("Method not implemented."); - } - - static saveCorrespondenceAddressToSession (session: Session, req: Request, ukAddresses: UKAddress[], inputPremise: string): void { - const acspData: ACSPData = session?.getExtraData(USER_DATA)!; + saveCorrespondenceAddressToSession (acspData :ACSPData, req: Request, ukAddresses: UKAddress[], inputPremise: string) { let address = { premise: "", @@ -50,11 +44,11 @@ export class CorrespondenceAddressAutoLookService { const userAddresses: Array
= acspData?.addresses ? acspData.addresses : []; userAddresses.push(correspondenceAddress); acspData.addresses = userAddresses; - saveDataInSession(req, USER_DATA, acspData); + //saveDataInSession(req, USER_DATA, acspData); + return acspData; } - public saveAddressListToSession (session: Session, req: Request, ukAddresses: UKAddress[]): void { - const ACSPData: ACSPData = session?.getExtraData(USER_DATA)!; + saveAddressListToSession (acspData: ACSPData, req: Request, ukAddresses: UKAddress[]) { const addressList: Array
= []; for (const ukAddress of ukAddresses) { @@ -72,8 +66,9 @@ export class CorrespondenceAddressAutoLookService { } // Save the list of addresses to the session - ACSPData.addresses = addressList; - saveDataInSession(req, ADDRESS_LIST, addressList); + acspData.addresses = addressList; + //saveDataInSession(req, ADDRESS_LIST, addressList); + return acspData; } } diff --git a/src/main/services/correspondence-address/address-details.ts b/src/main/services/correspondence-address/address-details.ts index e15c5ada..433cae9e 100644 --- a/src/main/services/correspondence-address/address-details.ts +++ b/src/main/services/correspondence-address/address-details.ts @@ -4,7 +4,7 @@ import { ACSPData } from "../../model/ACSPData"; import { CORRESPONDENCE_ADDRESS } from "../../common/__utils/constants"; export class CorrespondenceAddressDetailsService { - static saveCorrespondenceDetailsAddress (req: Request, acspData: ACSPData, selectPremise: string): void { + saveCorrespondenceDetailsAddress(req: Request, acspData: ACSPData, selectPremise: string): void { const addressList = acspData.addresses!; for (const ukAddress of addressList) { if (ukAddress.propertyDetails!.toUpperCase() === selectPremise.toUpperCase()) { diff --git a/src/main/services/correspondence-address/address-manual.ts b/src/main/services/correspondence-address/address-manual.ts index a8c4ff79..3f1c6c88 100644 --- a/src/main/services/correspondence-address/address-manual.ts +++ b/src/main/services/correspondence-address/address-manual.ts @@ -5,7 +5,7 @@ import { saveDataInSession } from "../../common/__utils/sessionHelper"; import { USER_DATA } from "../../common/__utils/constants"; export class CorrespondenceAddressManualService { - static saveCorrespondenceManualAddress (req: Request, acspData: ACSPData): void { + saveCorrespondenceManualAddress(req: Request, acspData: ACSPData): void { const correspondenceAddress: Address = { propertyDetails: req.body.addressPropertyDetails, line1: req.body.addressLine1, From e18a718719c8310f54f87847f38c37d7192ff665 Mon Sep 17 00:00:00 2001 From: hemerem-ch Date: Wed, 27 Mar 2024 13:23:06 +0000 Subject: [PATCH 05/14] -changes to address service --- .../services/correspondence-address/address-autolookup.ts | 4 ++-- src/main/services/correspondence-address/address-details.ts | 2 +- src/main/services/correspondence-address/address-manual.ts | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/main/services/correspondence-address/address-autolookup.ts b/src/main/services/correspondence-address/address-autolookup.ts index 7b3ecb73..441a53b3 100644 --- a/src/main/services/correspondence-address/address-autolookup.ts +++ b/src/main/services/correspondence-address/address-autolookup.ts @@ -44,7 +44,7 @@ export class CorrespondenceAddressAutoLookService { const userAddresses: Array
= acspData?.addresses ? acspData.addresses : []; userAddresses.push(correspondenceAddress); acspData.addresses = userAddresses; - //saveDataInSession(req, USER_DATA, acspData); + // saveDataInSession(req, USER_DATA, acspData); return acspData; } @@ -67,7 +67,7 @@ export class CorrespondenceAddressAutoLookService { } // Save the list of addresses to the session acspData.addresses = addressList; - //saveDataInSession(req, ADDRESS_LIST, addressList); + // saveDataInSession(req, ADDRESS_LIST, addressList); return acspData; } } diff --git a/src/main/services/correspondence-address/address-details.ts b/src/main/services/correspondence-address/address-details.ts index 433cae9e..d8a1fc17 100644 --- a/src/main/services/correspondence-address/address-details.ts +++ b/src/main/services/correspondence-address/address-details.ts @@ -4,7 +4,7 @@ import { ACSPData } from "../../model/ACSPData"; import { CORRESPONDENCE_ADDRESS } from "../../common/__utils/constants"; export class CorrespondenceAddressDetailsService { - saveCorrespondenceDetailsAddress(req: Request, acspData: ACSPData, selectPremise: string): void { + saveCorrespondenceDetailsAddress (req: Request, acspData: ACSPData, selectPremise: string): void { const addressList = acspData.addresses!; for (const ukAddress of addressList) { if (ukAddress.propertyDetails!.toUpperCase() === selectPremise.toUpperCase()) { diff --git a/src/main/services/correspondence-address/address-manual.ts b/src/main/services/correspondence-address/address-manual.ts index 3f1c6c88..d003cca9 100644 --- a/src/main/services/correspondence-address/address-manual.ts +++ b/src/main/services/correspondence-address/address-manual.ts @@ -5,7 +5,7 @@ import { saveDataInSession } from "../../common/__utils/sessionHelper"; import { USER_DATA } from "../../common/__utils/constants"; export class CorrespondenceAddressManualService { - saveCorrespondenceManualAddress(req: Request, acspData: ACSPData): void { + saveCorrespondenceManualAddress (req: Request, acspData: ACSPData): void { const correspondenceAddress: Address = { propertyDetails: req.body.addressPropertyDetails, line1: req.body.addressLine1, From 26e09fd34e000b8df85cc31923047ba804fd3d39 Mon Sep 17 00:00:00 2001 From: hemerem-ch Date: Wed, 27 Mar 2024 14:35:42 +0000 Subject: [PATCH 06/14] -refactor and code cleaning --- .../correspondenceAddressAutoLookupController.ts | 4 ++-- .../services/correspondence-address/address-autolookup.ts | 6 ++---- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/src/main/controllers/features/sole-trader/correspondenceAddressAutoLookupController.ts b/src/main/controllers/features/sole-trader/correspondenceAddressAutoLookupController.ts index 0362ed70..f419b1ce 100644 --- a/src/main/controllers/features/sole-trader/correspondenceAddressAutoLookupController.ts +++ b/src/main/controllers/features/sole-trader/correspondenceAddressAutoLookupController.ts @@ -59,12 +59,12 @@ export const post = async (req: Request, res: Response, next: NextFunction) => { getAddressFromPostcode(postcode).then((ukAddresses) => { if (correspondencePremise !== "" && ukAddresses.find((address) => address.premise === correspondencePremise)) { const autoLookupSessionservice = new CorrespondenceAddressAutoLookService(); - autoLookupSessionservice.saveCorrespondenceAddressToSession(acspData, req, ukAddresses, correspondencePremise); + autoLookupSessionservice.saveCorrespondenceAddress(acspData, ukAddresses, correspondencePremise); res.redirect(addLangToUrl(BASE_URL + SOLE_TRADER_CORRESPONDENCE_ADDRESS_CONFIRM, lang)); } else { const autoLookupListservice = new CorrespondenceAddressAutoLookService(); - autoLookupListservice.saveAddressListToSession(acspData, req, ukAddresses); + autoLookupListservice.saveAddressListToSession(acspData, ukAddresses); const nextPageUrl = addLangToUrl(BASE_URL + SOLE_TRADER_AUTO_LOOKUP_ADDRESS_LIST, lang); res.redirect(nextPageUrl); diff --git a/src/main/services/correspondence-address/address-autolookup.ts b/src/main/services/correspondence-address/address-autolookup.ts index 441a53b3..13294d6c 100644 --- a/src/main/services/correspondence-address/address-autolookup.ts +++ b/src/main/services/correspondence-address/address-autolookup.ts @@ -8,7 +8,7 @@ import { Address } from "../../model/Address"; import { getCountryFromKey } from "../../utils/web"; export class CorrespondenceAddressAutoLookService { - saveCorrespondenceAddressToSession (acspData :ACSPData, req: Request, ukAddresses: UKAddress[], inputPremise: string) { + saveCorrespondenceAddress (acspData :ACSPData, ukAddresses: UKAddress[], inputPremise: string) { let address = { premise: "", @@ -44,11 +44,10 @@ export class CorrespondenceAddressAutoLookService { const userAddresses: Array
= acspData?.addresses ? acspData.addresses : []; userAddresses.push(correspondenceAddress); acspData.addresses = userAddresses; - // saveDataInSession(req, USER_DATA, acspData); return acspData; } - saveAddressListToSession (acspData: ACSPData, req: Request, ukAddresses: UKAddress[]) { + saveAddressListToSession (acspData: ACSPData, ukAddresses: UKAddress[]) { const addressList: Array
= []; for (const ukAddress of ukAddresses) { @@ -67,7 +66,6 @@ export class CorrespondenceAddressAutoLookService { } // Save the list of addresses to the session acspData.addresses = addressList; - // saveDataInSession(req, ADDRESS_LIST, addressList); return acspData; } } From 842c2724089f0c0469a96deda990cd3d58cb32cf Mon Sep 17 00:00:00 2001 From: hemerem-ch Date: Wed, 27 Mar 2024 14:47:31 +0000 Subject: [PATCH 07/14] -refactor and code cleaning --- .../services/correspondence-address/address-autolookup.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/services/correspondence-address/address-autolookup.ts b/src/main/services/correspondence-address/address-autolookup.ts index 13294d6c..d7435782 100644 --- a/src/main/services/correspondence-address/address-autolookup.ts +++ b/src/main/services/correspondence-address/address-autolookup.ts @@ -8,7 +8,7 @@ import { Address } from "../../model/Address"; import { getCountryFromKey } from "../../utils/web"; export class CorrespondenceAddressAutoLookService { - saveCorrespondenceAddress (acspData :ACSPData, ukAddresses: UKAddress[], inputPremise: string) { + saveCorrespondenceAddress (acspData :ACSPData, ukAddresses: UKAddress[], inputPremise: string): ACSPData { let address = { premise: "", @@ -47,7 +47,7 @@ export class CorrespondenceAddressAutoLookService { return acspData; } - saveAddressListToSession (acspData: ACSPData, ukAddresses: UKAddress[]) { + saveAddressListToSession (acspData: ACSPData, ukAddresses: UKAddress[]): ACSPData { const addressList: Array
= []; for (const ukAddress of ukAddresses) { From 43e752cdb77b273d03ba4fdc91d1716a374b3f77 Mon Sep 17 00:00:00 2001 From: hemerem-ch Date: Wed, 27 Mar 2024 14:57:37 +0000 Subject: [PATCH 08/14] -refactor and code cleaning --- .../sole-trader/correspondenceAddressManualController.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/controllers/features/sole-trader/correspondenceAddressManualController.ts b/src/main/controllers/features/sole-trader/correspondenceAddressManualController.ts index f7709ab3..28bf40fb 100644 --- a/src/main/controllers/features/sole-trader/correspondenceAddressManualController.ts +++ b/src/main/controllers/features/sole-trader/correspondenceAddressManualController.ts @@ -47,8 +47,8 @@ export const post = async (req: Request, res: Response, next: NextFunction) => { lastName: acspData?.lastName }); } else { - const AddressManualservice = new CorrespondenceAddressManualService(); - AddressManualservice.saveCorrespondenceManualAddress(req, acspData); + const addressManualservice = new CorrespondenceAddressManualService(); + addressManualservice.saveCorrespondenceManualAddress(req, acspData); res.redirect(addLangToUrl(BASE_URL + SOLE_TRADER_CORRESPONDENCE_ADDRESS_CONFIRM, lang)); } From ef26094672075c22715486eba53c03f88926e3d7 Mon Sep 17 00:00:00 2001 From: hemerem-ch Date: Wed, 27 Mar 2024 15:01:20 +0000 Subject: [PATCH 09/14] -refactor and code cleaning --- src/main/validation/correspondenceAddressAutoLookup.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/validation/correspondenceAddressAutoLookup.ts b/src/main/validation/correspondenceAddressAutoLookup.ts index aaf29a9d..6ed51ddb 100644 --- a/src/main/validation/correspondenceAddressAutoLookup.ts +++ b/src/main/validation/correspondenceAddressAutoLookup.ts @@ -6,7 +6,7 @@ const addressPostcodevaild:RegExp = /^[A-Za-z0-9\s]*$/; export const correspondenceAddressAutoLookupValidator = [ - body("postCode").trim().notEmpty().withMessage("correspondenceLookUpAddressNoPostCode").bail() + body("postCode").trim().toUpperCase().notEmpty().withMessage("correspondenceLookUpAddressNoPostCode").bail() .matches(addressPostcodevaild).withMessage("invalidPostcodeFormat").bail() .matches(addressUKPostcodeFormat).withMessage("invalidAddressPostcode").bail() .isLength({ min: 5, max: 50 }).withMessage("invalidAddressPostcode"), From 7283a0947dc02d22c3c573ca1e390564b80242e8 Mon Sep 17 00:00:00 2001 From: hemerem-ch Date: Wed, 27 Mar 2024 16:27:24 +0000 Subject: [PATCH 10/14] -refactor and code cleaning --- .../address-autolookup.ts | 20 ++++++------------- 1 file changed, 6 insertions(+), 14 deletions(-) diff --git a/src/main/services/correspondence-address/address-autolookup.ts b/src/main/services/correspondence-address/address-autolookup.ts index d7435782..91dfc2dd 100644 --- a/src/main/services/correspondence-address/address-autolookup.ts +++ b/src/main/services/correspondence-address/address-autolookup.ts @@ -21,31 +21,23 @@ export class CorrespondenceAddressAutoLookService { }; for (const ukAddress of ukAddresses) { if (ukAddress.premise === inputPremise) { - address = { + const correspondenceAddress: Address = { propertyDetails: ukAddress.premise, - premise: ukAddress.premise, + //premise: ukAddress.premise, line1: ukAddress.addressLine1, line2: ukAddress.addressLine2!, town: ukAddress.postTown, country: getCountryFromKey(ukAddress.country), postcode: ukAddress.postcode }; + + acspData.addresses = [correspondenceAddress]; + break; } } - - const correspondenceAddress: Address = { - propertyDetails: address.premise, - line1: address.line1, - line2: address.line2, - town: address.town, - country: address.country, - postcode: address.postcode - }; - const userAddresses: Array
= acspData?.addresses ? acspData.addresses : []; - userAddresses.push(correspondenceAddress); - acspData.addresses = userAddresses; return acspData; } + saveAddressListToSession (acspData: ACSPData, ukAddresses: UKAddress[]): ACSPData { From b2f3188590f0a0bbcdcb593e0c1ce14557afea08 Mon Sep 17 00:00:00 2001 From: hemerem-ch Date: Wed, 27 Mar 2024 16:27:56 +0000 Subject: [PATCH 11/14] -refactor and code cleaning --- .../services/correspondence-address/address-autolookup.ts | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/main/services/correspondence-address/address-autolookup.ts b/src/main/services/correspondence-address/address-autolookup.ts index 91dfc2dd..92c9f3ef 100644 --- a/src/main/services/correspondence-address/address-autolookup.ts +++ b/src/main/services/correspondence-address/address-autolookup.ts @@ -10,7 +10,7 @@ import { getCountryFromKey } from "../../utils/web"; export class CorrespondenceAddressAutoLookService { saveCorrespondenceAddress (acspData :ACSPData, ukAddresses: UKAddress[], inputPremise: string): ACSPData { - let address = { + const address = { premise: "", propertyDetails: "", line1: "", @@ -23,7 +23,7 @@ export class CorrespondenceAddressAutoLookService { if (ukAddress.premise === inputPremise) { const correspondenceAddress: Address = { propertyDetails: ukAddress.premise, - //premise: ukAddress.premise, + // premise: ukAddress.premise, line1: ukAddress.addressLine1, line2: ukAddress.addressLine2!, town: ukAddress.postTown, @@ -37,7 +37,6 @@ export class CorrespondenceAddressAutoLookService { } return acspData; } - saveAddressListToSession (acspData: ACSPData, ukAddresses: UKAddress[]): ACSPData { From 8d1cef3690b9140b533efc39d4e65fee578d9ff4 Mon Sep 17 00:00:00 2001 From: hemerem-ch Date: Wed, 27 Mar 2024 16:59:03 +0000 Subject: [PATCH 12/14] -refactor and code cleaning --- .../correspondence-address/address-autolookup.ts | 14 ++------------ 1 file changed, 2 insertions(+), 12 deletions(-) diff --git a/src/main/services/correspondence-address/address-autolookup.ts b/src/main/services/correspondence-address/address-autolookup.ts index 92c9f3ef..322f7311 100644 --- a/src/main/services/correspondence-address/address-autolookup.ts +++ b/src/main/services/correspondence-address/address-autolookup.ts @@ -8,22 +8,12 @@ import { Address } from "../../model/Address"; import { getCountryFromKey } from "../../utils/web"; export class CorrespondenceAddressAutoLookService { - saveCorrespondenceAddress (acspData :ACSPData, ukAddresses: UKAddress[], inputPremise: string): ACSPData { + saveCorrespondenceAddress(acspData: ACSPData, ukAddresses: UKAddress[], inputPremise: string): ACSPData { - const address = { - premise: "", - propertyDetails: "", - line1: "", - line2: "", - town: "", - country: "", - postcode: "" - }; for (const ukAddress of ukAddresses) { if (ukAddress.premise === inputPremise) { const correspondenceAddress: Address = { propertyDetails: ukAddress.premise, - // premise: ukAddress.premise, line1: ukAddress.addressLine1, line2: ukAddress.addressLine2!, town: ukAddress.postTown, @@ -38,7 +28,7 @@ export class CorrespondenceAddressAutoLookService { return acspData; } - saveAddressListToSession (acspData: ACSPData, ukAddresses: UKAddress[]): ACSPData { + saveAddressListToSession(acspData: ACSPData, ukAddresses: UKAddress[]): ACSPData { const addressList: Array
= []; for (const ukAddress of ukAddresses) { From 4db8528c6074d015267e0696b085ac1faa40fbaa Mon Sep 17 00:00:00 2001 From: hemerem-ch Date: Wed, 27 Mar 2024 17:02:18 +0000 Subject: [PATCH 13/14] -removed import and piece of code not needed --- .../sole-trader/correspodanceAddressDetailsController.ts | 7 +++---- .../correspondenceAddressAutoLookupController.ts | 4 ---- .../sole-trader/correspondenceAddressManualController.ts | 2 -- .../services/correspondence-address/address-autolookup.ts | 8 ++------ 4 files changed, 5 insertions(+), 16 deletions(-) diff --git a/src/main/controllers/features/sole-trader/correspodanceAddressDetailsController.ts b/src/main/controllers/features/sole-trader/correspodanceAddressDetailsController.ts index 2494ae4c..8188ae1d 100644 --- a/src/main/controllers/features/sole-trader/correspodanceAddressDetailsController.ts +++ b/src/main/controllers/features/sole-trader/correspodanceAddressDetailsController.ts @@ -6,13 +6,12 @@ import { selectLang, addLangToUrl, getLocalesService, getLocaleInfo } from "../. import { SOLE_TRADER_AUTO_LOOKUP_ADDRESS_LIST, SOLE_TRADER_AUTO_LOOKUP_ADDRESS, SOLE_TRADER_CORRESPONDENCE_ADDRESS_CONFIRM, BASE_URL, SOLE_TRADER_MANUAL_CORRESPONDENCE_ADDRESS } from "../../../types/pageURL"; import { ACSPData } from "../../../model/ACSPData"; import { Session } from "@companieshouse/node-session-handler"; -import { CORRESPONDENCE_ADDRESS, USER_DATA } from "../../../common/__utils/constants"; -import { saveDataInSession } from "../../../common/__utils/sessionHelper"; +import { USER_DATA } from "../../../common/__utils/constants"; import { CorrespondenceAddressDetailsService } from "../../../services/correspondence-address/address-details"; export const get = async (req: Request, res: Response, next: NextFunction) => { const session: Session = req.session as any as Session; - const acspData : ACSPData = session?.getExtraData(USER_DATA)!; + const acspData: ACSPData = session?.getExtraData(USER_DATA)!; const lang = selectLang(req.query.lang); const locales = getLocalesService(); @@ -31,7 +30,7 @@ export const get = async (req: Request, res: Response, next: NextFunction) => { export const post = async (req: Request, res: Response, next: NextFunction) => { const session: Session = req.session as any as Session; - const acspData : ACSPData = session?.getExtraData(USER_DATA)!; + const acspData: ACSPData = session?.getExtraData(USER_DATA)!; try { const errorList = validationResult(req); diff --git a/src/main/controllers/features/sole-trader/correspondenceAddressAutoLookupController.ts b/src/main/controllers/features/sole-trader/correspondenceAddressAutoLookupController.ts index f419b1ce..33e995d2 100644 --- a/src/main/controllers/features/sole-trader/correspondenceAddressAutoLookupController.ts +++ b/src/main/controllers/features/sole-trader/correspondenceAddressAutoLookupController.ts @@ -1,17 +1,13 @@ - import { NextFunction, Request, Response } from "express"; import { ValidationError, validationResult } from "express-validator"; import { FormattedValidationErrors, formatValidationError } from "../../../validation/validation"; import * as config from "../../../config"; import { getAddressFromPostcode } from "../../../services/postcode-lookup-service"; -import { getCountryFromKey } from "../../../utils/web"; import { selectLang, addLangToUrl, getLocalesService, getLocaleInfo } from "../../../utils/localise"; import { BASE_URL, SOLE_TRADER_AUTO_LOOKUP_ADDRESS, SOLE_TRADER_AUTO_LOOKUP_ADDRESS_LIST, SOLE_TRADER_CORRESPONDENCE_ADDRESS_CONFIRM, SOLE_TRADER_SECTOR_YOU_WORK_IN, SOLE_TRADER_MANUAL_CORRESPONDENCE_ADDRESS } from "../../../types/pageURL"; -import { Address } from "../../../model/Address"; import { ACSPData } from "../../../model/ACSPData"; import { Session } from "@companieshouse/node-session-handler"; import { USER_DATA } from "../../../common/__utils/constants"; -import { saveDataInSession } from "../../../common/__utils/sessionHelper"; import CorrespondenceAddressAutoLookService from "../../../services/correspondence-address/address-autolookup"; export const get = async (req: Request, res: Response, next: NextFunction) => { diff --git a/src/main/controllers/features/sole-trader/correspondenceAddressManualController.ts b/src/main/controllers/features/sole-trader/correspondenceAddressManualController.ts index 28bf40fb..7e0d4430 100644 --- a/src/main/controllers/features/sole-trader/correspondenceAddressManualController.ts +++ b/src/main/controllers/features/sole-trader/correspondenceAddressManualController.ts @@ -4,11 +4,9 @@ import * as config from "../../../config"; import { FormattedValidationErrors, formatValidationError } from "../../../validation/validation"; import { selectLang, addLangToUrl, getLocalesService, getLocaleInfo } from "../../../utils/localise"; import { SOLE_TRADER_CORRESPONDENCE_ADDRESS_CONFIRM, SOLE_TRADER_AUTO_LOOKUP_ADDRESS, SOLE_TRADER_MANUAL_CORRESPONDENCE_ADDRESS, BASE_URL } from "../../../types/pageURL"; -import { Address } from "../../../model/Address"; import { ACSPData } from "../../../model/ACSPData"; import { Session } from "@companieshouse/node-session-handler"; import { USER_DATA } from "../../../common/__utils/constants"; -import { saveDataInSession } from "../../../common/__utils/sessionHelper"; import { CorrespondenceAddressManualService } from "../../../services/correspondence-address/address-manual"; export const get = async (req: Request, res: Response, next: NextFunction) => { diff --git a/src/main/services/correspondence-address/address-autolookup.ts b/src/main/services/correspondence-address/address-autolookup.ts index 322f7311..20209a4e 100644 --- a/src/main/services/correspondence-address/address-autolookup.ts +++ b/src/main/services/correspondence-address/address-autolookup.ts @@ -1,14 +1,10 @@ import { UKAddress } from "@companieshouse/api-sdk-node/dist/services/postcode-lookup/types"; -import { Session } from "@companieshouse/node-session-handler"; -import { Request } from "express"; -import { ADDRESS_LIST, USER_DATA } from "../../common/__utils/constants"; -import { saveDataInSession } from "../../common/__utils/sessionHelper"; import { ACSPData } from "../../model/ACSPData"; import { Address } from "../../model/Address"; import { getCountryFromKey } from "../../utils/web"; export class CorrespondenceAddressAutoLookService { - saveCorrespondenceAddress(acspData: ACSPData, ukAddresses: UKAddress[], inputPremise: string): ACSPData { + saveCorrespondenceAddress (acspData: ACSPData, ukAddresses: UKAddress[], inputPremise: string): ACSPData { for (const ukAddress of ukAddresses) { if (ukAddress.premise === inputPremise) { @@ -28,7 +24,7 @@ export class CorrespondenceAddressAutoLookService { return acspData; } - saveAddressListToSession(acspData: ACSPData, ukAddresses: UKAddress[]): ACSPData { + saveAddressListToSession (acspData: ACSPData, ukAddresses: UKAddress[]): ACSPData { const addressList: Array
= []; for (const ukAddress of ukAddresses) { From dc7ec761f0a43413bc8603af2d92656d72c4afe1 Mon Sep 17 00:00:00 2001 From: hemerem-ch Date: Thu, 28 Mar 2024 09:37:26 +0000 Subject: [PATCH 14/14] -removed import and piece of code not needed --- src/main/services/correspondence-address/address-autolookup.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/src/main/services/correspondence-address/address-autolookup.ts b/src/main/services/correspondence-address/address-autolookup.ts index 20209a4e..1589dd37 100644 --- a/src/main/services/correspondence-address/address-autolookup.ts +++ b/src/main/services/correspondence-address/address-autolookup.ts @@ -41,7 +41,6 @@ export class CorrespondenceAddressAutoLookService { addressList.push(address); } - // Save the list of addresses to the session acspData.addresses = addressList; return acspData; }