|
1 | 1 | import { UPDATE_BENEFICIAL_OWNER_BO_MO_REVIEW_URL, UPDATE_BENEFICIAL_OWNER_TYPE_URL, UPDATE_REVIEW_INDIVIDUAL_MANAGING_OFFICER_PAGE, RELEVANT_PERIOD_QUERY_PARAM } from "../../config"; |
2 | 2 | import { NextFunction, Request, Response } from "express"; |
3 | | -import { getApplicationData, mapDataObjectToFields, removeFromApplicationData, setApplicationData } from "../../utils/application.data"; |
| 3 | +import { getApplicationData, removeFromApplicationData, setApplicationData } from "../../utils/application.data"; |
4 | 4 | import { logger } from "../../utils/logger"; |
5 | 5 | import { ManagingOfficerKey } from "../../model/managing.officer.model"; |
6 | 6 | import { setReviewedDateOfBirth } from "./update.review.beneficial.owner.individual"; |
7 | 7 | import { Session } from "@companieshouse/node-session-handler"; |
8 | 8 | import { ApplicationDataType } from "../../model"; |
9 | 9 | import { v4 as uuidv4 } from "uuid"; |
10 | 10 | import { saveAndContinue } from "../../utils/save.and.continue"; |
11 | | -import { AddressKeys, InputDate } from "../../model/data.types.model"; |
| 11 | +import { InputDate } from "../../model/data.types.model"; |
12 | 12 | import { setOfficerData } from "../../utils/managing.officer.individual"; |
13 | 13 | import { HaveDayOfBirthKey, ResignedOnKey } from "../../model/date.model"; |
14 | 14 | import { addResignedDateToTemplateOptions } from "../../utils/update/ceased_date_util"; |
15 | | -import { UsualResidentialAddressKey, UsualResidentialAddressKeys } from "../../model/address.model"; |
16 | 15 | import { checkRelevantPeriod } from "../../utils/relevant.period"; |
| 16 | +import { fetchIndividualMOAddress } from "../../utils/update/review.managing.officer"; |
17 | 17 |
|
18 | 18 | export const get = async (req: Request, res: Response, next: NextFunction) => { |
19 | 19 | try { |
20 | 20 | logger.debugRequest(req, `${req.method} ${req.route.path}`); |
21 | 21 | const appData = await getApplicationData(req.session); |
22 | | - const index = req.query.index; |
| 22 | + const index = Number(req.query.index); |
23 | 23 |
|
24 | | - let dataToReview = {}, residentialAddress = {}; |
25 | | - |
26 | | - if (appData?.managing_officers_individual){ |
27 | | - dataToReview = appData?.managing_officers_individual[Number(index)]; |
28 | | - residentialAddress = (dataToReview) ? mapDataObjectToFields(dataToReview[UsualResidentialAddressKey], UsualResidentialAddressKeys, AddressKeys) : {}; |
29 | | - } |
| 24 | + const { dataToReview, residentialAddress, serviceAddress } = fetchIndividualMOAddress(appData, index); |
30 | 25 |
|
31 | 26 | const templateOptions = { |
32 | 27 | backLinkUrl: UPDATE_BENEFICIAL_OWNER_BO_MO_REVIEW_URL, |
33 | 28 | templateName: UPDATE_REVIEW_INDIVIDUAL_MANAGING_OFFICER_PAGE, |
34 | 29 | ...dataToReview, |
35 | | - ...residentialAddress |
| 30 | + ...residentialAddress, |
| 31 | + ...serviceAddress |
36 | 32 | }; |
37 | 33 |
|
38 | 34 | if (ResignedOnKey in dataToReview) { |
|
0 commit comments