-
Notifications
You must be signed in to change notification settings - Fork 0
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 bug issue #213
base: main
Are you sure you want to change the base?
Address bug issue #213
Changes from 7 commits
187a395
7c9f3d9
d6ced74
2950f45
f96e60d
55c713a
e18a718
26e09fd
842c272
43e752c
ef26094
7283a09
b2f3188
8d1cef3
4db8528
dc7ec76
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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,10 @@ 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<Address> = acspData?.addresses ? acspData.addresses : []; | ||
userAddress.push(correspondenceAddress); | ||
acspData.addresses = userAddress; | ||
saveDataInSession(req, USER_DATA, acspData); | ||
res.redirect(BASE_URL + SOLE_TRADER_CORRESPONDENCE_ADDRESS_CONFIRM); | ||
const AddressManualservice = new CorrespondenceAddressManualService(); | ||
AddressManualservice.saveCorrespondenceManualAddress(req, acspData); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. variable name needs to follow camel casing |
||
res.redirect(addLangToUrl(BASE_URL + SOLE_TRADER_CORRESPONDENCE_ADDRESS_CONFIRM, lang)); | ||
|
||
} | ||
} catch (error) { | ||
next(error); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
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 { | ||
saveCorrespondenceAddressToSession (acspData :ACSPData, req: Request, ukAddresses: UKAddress[], inputPremise: string) { | ||
|
||
sampankumar marked this conversation as resolved.
Show resolved
Hide resolved
|
||
let address = { | ||
premise: "", | ||
propertyDetails: "", | ||
line1: "", | ||
line2: "", | ||
town: "", | ||
country: "", | ||
postcode: "" | ||
}; | ||
for (const ukAddress of ukAddresses) { | ||
if (ukAddress.premise === inputPremise) { | ||
address = { | ||
propertyDetails: ukAddress.premise, | ||
premise: ukAddress.premise, | ||
line1: ukAddress.addressLine1, | ||
line2: ukAddress.addressLine2!, | ||
town: ukAddress.postTown, | ||
country: getCountryFromKey(ukAddress.country), | ||
postcode: ukAddress.postcode | ||
}; | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. you can break out of the loop once the match is found There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There is no difference between address and correspondenceAddress. Only one can be used |
||
} | ||
|
||
const correspondenceAddress: Address = { | ||
propertyDetails: address.premise, | ||
line1: address.line1, | ||
line2: address.line2, | ||
town: address.town, | ||
country: address.country, | ||
postcode: address.postcode | ||
}; | ||
const userAddresses: Array<Address> = acspData?.addresses ? acspData.addresses : []; | ||
userAddresses.push(correspondenceAddress); | ||
acspData.addresses = userAddresses; | ||
// saveDataInSession(req, USER_DATA, acspData); | ||
return acspData; | ||
} | ||
|
||
saveAddressListToSession (acspData: ACSPData, req: Request, ukAddresses: UKAddress[]) { | ||
|
||
const addressList: Array<Address> = []; | ||
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); | ||
|
||
} | ||
// Save the list of addresses to the session | ||
acspData.addresses = addressList; | ||
// saveDataInSession(req, ADDRESS_LIST, addressList); | ||
return acspData; | ||
} | ||
} | ||
|
||
export default CorrespondenceAddressAutoLookService; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 { | ||
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; | ||
} | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
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 { | ||
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<Address> = acspData?.addresses ? acspData.addresses : []; | ||
userAddress.push(correspondenceAddress); | ||
acspData.addresses = userAddress; | ||
saveDataInSession(req, USER_DATA, acspData); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
saveCorrespondenceAddress is enough no need to add "ToSession" in the name