Skip to content

Commit

Permalink
feat: fix issues causing journey failures
Browse files Browse the repository at this point in the history
  • Loading branch information
mwejuli-ch committed Jul 5, 2024
1 parent 52b7948 commit 0ab0482
Show file tree
Hide file tree
Showing 21 changed files with 69 additions and 53 deletions.
2 changes: 1 addition & 1 deletion src/controllers/beneficial.owner.type.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export const get = async (req: Request, res: Response, next: NextFunction) => {
}
};

export const post = async (req: Request, res: Response) => {
export const post = (req: Request, res: Response) => {
logger.debugRequest(req, `${req.method} ${req.route.path}`);

return res.redirect(getNextPage(req));
Expand Down
12 changes: 6 additions & 6 deletions src/controllers/overseas.name.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { getUrlWithParamsToPath, getUrlWithTransactionIdAndSubmissionId, transac
export const get = async (req: Request, res: Response, next: NextFunction) => {
try {
logger.debugRequest(req, `GET ${config.OVERSEAS_NAME_PAGE}`);

const appData: ApplicationData = await getApplicationData(req.session);

let backLinkUrl = config.INTERRUPT_CARD_URL;
Expand All @@ -33,17 +34,13 @@ export const get = async (req: Request, res: Response, next: NextFunction) => {

export const post = async (req: Request, res: Response, next: NextFunction) => {
try {

logger.debugRequest(req, `POST ${config.OVERSEAS_NAME_PAGE}`);

const session = req.session as Session;
const entityName = req.body[EntityNameKey];

setExtraData(req.session, {
...getApplicationData(req.session),
[EntityNameKey]: entityName
});

const appData: ApplicationData = await getApplicationData(session, req);
const appData: ApplicationData = await getApplicationData(session);
let nextPageUrl = config.PRESENTER_URL;

if (isActiveFeature(config.FEATURE_FLAG_ENABLE_SAVE_AND_RESUME_17102022)) {
Expand All @@ -52,6 +49,9 @@ export const post = async (req: Request, res: Response, next: NextFunction) => {
nextPageUrl = getUrlWithTransactionIdAndSubmissionId(config.PRESENTER_WITH_PARAMS_URL, appData[Transactionkey] as string, appData[OverseasEntityKey] as string);
}
}

setExtraData(req.session, { ...appData, [EntityNameKey]: entityName });

return res.redirect(nextPageUrl);
} catch (error) {
logger.errorRequest(req, error);
Expand Down
3 changes: 1 addition & 2 deletions src/controllers/presenter.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ import { isActiveFeature } from "../utils/feature.flag";
import { getUrlWithParamsToPath } from "../utils/url";

export const get = async (req: Request, res: Response, next: NextFunction) => {

let backLinkUrl = config.OVERSEAS_NAME_URL;
if (isActiveFeature(config.FEATURE_FLAG_ENABLE_REDIS_REMOVAL)){
backLinkUrl = getUrlWithParamsToPath(config.OVERSEAS_NAME_WITH_PARAMS_URL, req);
}

await getPresenterPage(req, res, next, config.PRESENTER_PAGE, backLinkUrl);
};

Expand All @@ -20,6 +20,5 @@ export const post = (req: Request, res: Response, next: NextFunction) => {
if (isActiveFeature(config.FEATURE_FLAG_ENABLE_REDIS_REMOVAL)){
nextPageUrl = getUrlWithParamsToPath(config.WHO_IS_MAKING_FILING_WITH_PARAMS_URL, req);
}

postPresenterPage(req, res, next, nextPageUrl, true);
};
10 changes: 7 additions & 3 deletions src/controllers/secure.register.filter.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,18 @@ import { getFilterPage, postFilterPage } from "../utils/secure.filter";
import { isActiveFeature } from "../utils/feature.flag";
import { getUrlWithParamsToPath } from "../utils/url";

export const get = (req: Request, res: Response, next: NextFunction) => {
export const get = async (req: Request, res: Response, next: NextFunction) => {
let backLinkUrl: string = config.SOLD_LAND_FILTER_URL;
if (isActiveFeature(config.FEATURE_FLAG_ENABLE_REDIS_REMOVAL)) {
backLinkUrl = getUrlWithParamsToPath(config.SOLD_LAND_FILTER_WITH_PARAMS_URL, req);
}
getFilterPage(req, res, next, config.SECURE_REGISTER_FILTER_PAGE, backLinkUrl);
await getFilterPage(req, res, next, config.SECURE_REGISTER_FILTER_PAGE, backLinkUrl);
};

export const post = async (req: Request, res: Response, next: NextFunction) => {
await postFilterPage(req, res, next, config.USE_PAPER_URL, config.INTERRUPT_CARD_URL);
let nextPageUrl = config.INTERRUPT_CARD_URL;
if (isActiveFeature(config.FEATURE_FLAG_ENABLE_REDIS_REMOVAL)) {
nextPageUrl = getUrlWithParamsToPath(config.INTERRUPT_CARD_WITH_PARAMS_URL, req);
}
await postFilterPage(req, res, next, config.USE_PAPER_URL, nextPageUrl);
};
7 changes: 6 additions & 1 deletion src/controllers/sold.land.filter.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export const get = async (req: Request, res: Response, next: NextFunction) => {
const appData: ApplicationData = await getApplicationData(req.session);

return res.render(config.SOLD_LAND_FILTER_PAGE, {
backLinkUrl: await getSoldLandFilterBackLink(),
backLinkUrl: getSoldLandFilterBackLink(),
templateName: config.SOLD_LAND_FILTER_PAGE,
[HasSoldLandKey]: appData?.[HasSoldLandKey]
});
Expand All @@ -35,6 +35,7 @@ export const get = async (req: Request, res: Response, next: NextFunction) => {

export const post = async (req: Request, res: Response, next: NextFunction) => {
try {

logger.debugRequest(req, `POST ${config.SOLD_LAND_FILTER_PAGE}`);

const session = req.session as Session;
Expand All @@ -54,12 +55,16 @@ export const post = async (req: Request, res: Response, next: NextFunction) => {
} else {
await updateOverseasEntity(req, session, appData);
}

nextPageUrl = config.SECURE_REGISTER_FILTER_URL;

if (isActiveFeature(config.FEATURE_FLAG_ENABLE_REDIS_REMOVAL)) {
nextPageUrl = getUrlWithTransactionIdAndSubmissionId(config.SECURE_REGISTER_FILTER_WITH_PARAMS_URL, appData[Transactionkey] as string, appData[OverseasEntityKey] as string);
}
}

setExtraData(session, appData);

return res.redirect(nextPageUrl);
} catch (error) {
logger.errorRequest(req, error);
Expand Down
4 changes: 2 additions & 2 deletions src/controllers/update/who.is.making.update.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@ export const get = async (req: Request, res: Response, next: NextFunction) => {
await getWhoIsFiling(req, res, next, WHO_IS_MAKING_UPDATE_PAGE, UPDATE_DO_YOU_WANT_TO_MAKE_OE_CHANGE_URL);
};

export const post = (req: Request, res: Response, next: NextFunction) => {
postWhoIsFiling(req, res, next, UPDATE_DUE_DILIGENCE_URL, UPDATE_DUE_DILIGENCE_OVERSEAS_ENTITY_URL);
export const post = async (req: Request, res: Response, next: NextFunction) => {
await postWhoIsFiling(req, res, next, UPDATE_DUE_DILIGENCE_URL, UPDATE_DUE_DILIGENCE_OVERSEAS_ENTITY_URL);
};
4 changes: 2 additions & 2 deletions src/controllers/who.is.making.filing.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@ export const get = async (req: Request, res: Response, next: NextFunction) => {
await getWhoIsFiling(req, res, next, WHO_IS_MAKING_FILING_PAGE, backLinkUrl);
};

export const post = (req: Request, res: Response, next: NextFunction) => {
export const post = async (req: Request, res: Response, next: NextFunction) => {
let nextPageUrl = DUE_DILIGENCE_URL;
let oeNextPageUrl = OVERSEAS_ENTITY_DUE_DILIGENCE_URL;
if (isActiveFeature(FEATURE_FLAG_ENABLE_REDIS_REMOVAL)) {
nextPageUrl = getUrlWithParamsToPath(DUE_DILIGENCE_WITH_PARAMS_URL, req);
oeNextPageUrl = getUrlWithParamsToPath(OVERSEAS_ENTITY_DUE_DILIGENCE_WITH_PARAMS_URL, req);
}
postWhoIsFiling(req, res, next, nextPageUrl, oeNextPageUrl);
await postWhoIsFiling(req, res, next, nextPageUrl, oeNextPageUrl);
};
2 changes: 1 addition & 1 deletion src/middleware/navigation/has.overseas.name.middleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { checkOverseasNameDetailsEntered, NavigationErrorMessage } from './check

export const hasOverseasName = async (req: Request, res: Response, next: NextFunction): Promise<void> => {
try {
if ( !checkOverseasNameDetailsEntered(await getApplicationData(req.session)) ) {
if (!checkOverseasNameDetailsEntered(await getApplicationData(req.session))) {
logger.infoRequest(req, NavigationErrorMessage);
return res.redirect(SOLD_LAND_FILTER_URL);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { OVERSEAS_ENTITY_QUERY_URL, SECURE_UPDATE_FILTER_URL } from '../../../co
import { getApplicationData } from "../../../utils/application.data";
import { checkOverseasEntityNumberEntered, checkHasOverseasEntity, checkHasDateOfCreation, NavigationErrorMessage } from '../check.condition';

export const hasOverseasEntityNumber = async (req: Request, res: Response, next: NextFunction): Promise<void> => {
export const hasOverseasEntityNumber = async (req: Request, res: Response, next: NextFunction): Promise<void> => {
try {
if (!checkOverseasEntityNumberEntered(await getApplicationData(req.session))) {
logger.infoRequest(req, NavigationErrorMessage);
Expand Down
5 changes: 1 addition & 4 deletions src/model/navigation.model.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
import { ApplicationData } from "./application.model";
import { Request } from "express";

export interface Navigation {
[x: string]: {
currentPage: string;
previousPage: ((data?: ApplicationData, req?: Request) => string);
previousPage: Function;
nextPage: string[];
};
}
2 changes: 1 addition & 1 deletion src/service/overseas.entities.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export const createOverseasEntity = async (

export const updateOverseasEntity = async (req: Request, session: Session, data?: ApplicationData) => {

const appData: ApplicationData = typeof data !== "undefined" ? data : await getApplicationData(session);
const appData: ApplicationData = typeof data !== "undefined" ? data : await getApplicationData(session, req);

const transactionId = appData[Transactionkey] as string;
const overseasEntityId = appData[OverseasEntityKey] as string;
Expand Down
2 changes: 1 addition & 1 deletion src/service/payment.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export const startPaymentsSession = async (
): Promise<string> => {

setExtraData(session, {
...getApplicationData(session),
...(await getApplicationData(session)),
[Transactionkey]: transactionId,
[OverseasEntityKey]: overseasEntityId
});
Expand Down
6 changes: 3 additions & 3 deletions src/service/transaction.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { makeApiCallWithRetry } from "./retry.handler.service";
import { EntityNameKey, EntityNumberKey } from "../model/data.types.model";

export const postTransaction = async (req: Request, session: Session): Promise<string> => {
const applicationData: ApplicationData = await getApplicationData(session);
const applicationData: ApplicationData = await getApplicationData(session, req);
const companyName = applicationData[EntityNameKey];
const companyNumber = applicationData[EntityNumberKey];

Expand All @@ -32,9 +32,9 @@ export const postTransaction = async (req: Request, session: Session): Promise<s
);

if (!response.httpStatusCode || response.httpStatusCode >= 400) {
throw createAndLogErrorRequest(req, `'postTransaction' for company number '${companyNumber}' with name '${companyName}' returned HTTP status code ${response.httpStatusCode}`);
throw createAndLogErrorRequest(req, `'>>error:>>>>>>>>postTransaction' for company number '${companyNumber}' with name '${companyName}' returned HTTP status code ${response.httpStatusCode}`);
} else if (!response.resource) {
throw createAndLogErrorRequest(req, `'postTransaction' for company number '${companyNumber}' with name '${companyName}' returned no response`);
throw createAndLogErrorRequest(req, `'>>error:>>>>>>>>>postTransaction' for company number '${companyNumber}' with name '${companyName}' returned no response`);
}

logger.infoRequest(req, `Response from 'postTransaction' for company number '${companyNumber}' with name '${companyName}': ${JSON.stringify(response)}`);
Expand Down
25 changes: 18 additions & 7 deletions src/utils/application.data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Session } from '@companieshouse/node-session-handler';
import { Request } from "express";

import { createAndLogErrorRequest } from './logger';
import { ID } from '../model/data.types.model';
import { ID, OverseasEntityKey, Transactionkey } from '../model/data.types.model';

import {
ApplicationData,
Expand All @@ -23,22 +23,33 @@ import {
PARAM_BENEFICIAL_OWNER_INDIVIDUAL,
PARAM_BENEFICIAL_OWNER_OTHER,
PARAM_MANAGING_OFFICER_CORPORATE,
PARAM_MANAGING_OFFICER_INDIVIDUAL
PARAM_MANAGING_OFFICER_INDIVIDUAL,
ROUTE_PARAM_TRANSACTION_ID,
ROUTE_PARAM_SUBMISSION_ID
} from '../config';

import { BeneficialOwnerCorporate } from '@companieshouse/api-sdk-node/dist/services/overseas-entities';
import { Remove } from 'model/remove.type.model';
import { isActiveFeature } from "./feature.flag";
import { getOverseasEntity } from "../service/overseas.entities.service";
import * as config from "../config";

export const getApplicationData = async (session: Session | undefined, req?: Request): Promise<ApplicationData> => {
if (!isActiveFeature(FEATURE_FLAG_ENABLE_REDIS_REMOVAL) || typeof req === "undefined") {
if (typeof req === "undefined" || !isActiveFeature(FEATURE_FLAG_ENABLE_REDIS_REMOVAL)) {
return session?.getExtraData(APPLICATION_DATA_KEY) || {} as ApplicationData;
}
const transactionId: string = req.params[config.ROUTE_PARAM_TRANSACTION_ID] ? req.params[config.ROUTE_PARAM_TRANSACTION_ID] : "";
const submissionId: string = req.params[config.ROUTE_PARAM_SUBMISSION_ID] ? req.params[config.ROUTE_PARAM_SUBMISSION_ID] : "";
return await getOverseasEntity(req, transactionId, submissionId);

const transactionId: string = req.params[ROUTE_PARAM_TRANSACTION_ID] ?? "";
const submissionId: string = req.params[ROUTE_PARAM_SUBMISSION_ID] ?? "";

if (transactionId === "" && submissionId === "") {
return {};
}

const appData = await getOverseasEntity(req, transactionId, submissionId);
appData[Transactionkey] = transactionId;
appData[OverseasEntityKey] = submissionId;

return appData;
};

export const deleteApplicationData = (session: Session | undefined): boolean | undefined => {
Expand Down
2 changes: 1 addition & 1 deletion src/utils/navigation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ export const NAVIGATION: Navigation = {
},
[config.OVERSEAS_ENTITY_PRESENTER_URL]: {
currentPage: config.UPDATE_PRESENTER_PAGE,
previousPage:async (appData: ApplicationData, req: Request) => await getOverseasEntityPresenterBackLink(req),
previousPage: async (appData: ApplicationData, req: Request) => await getOverseasEntityPresenterBackLink(req),
nextPage: [config.UPDATE_DO_YOU_WANT_TO_MAKE_OE_CHANGE_PAGE]
},
[config.UPDATE_DO_YOU_WANT_TO_MAKE_OE_CHANGE_URL]: {
Expand Down
4 changes: 2 additions & 2 deletions src/utils/presenter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export const getPresenterPage = async (req: Request, res: Response, next: NextFu
const appData: ApplicationData = await getApplicationData(req.session);
const presenter = appData[PresenterKey];

if (await isRemoveJourney(req)){
if (await isRemoveJourney(req)) {
return res.render(templateName, {
journey: config.JourneyType.remove,
backLinkUrl: `${config.UPDATE_OVERSEAS_ENTITY_CONFIRM_URL}${config.JOURNEY_REMOVE_QUERY_PARAM}`,
Expand All @@ -28,7 +28,7 @@ export const getPresenterPage = async (req: Request, res: Response, next: NextFu
}

return res.render(templateName, {
backLinkUrl: backLinkUrl,
backLinkUrl,
templateName: templateName,
...presenter
});
Expand Down
6 changes: 3 additions & 3 deletions src/utils/secure.filter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export const getFilterPage = async (req: Request, res: Response, next: NextFunct
logger.debugRequest(req, `${req.method} ${req.route.path}`);
const appData: ApplicationData = await getApplicationData(req.session);

if (await isRemoveJourney(req)){
if (await isRemoveJourney(req)) {
return res.render(templateName, {
journey: config.JourneyType.remove,
backLinkUrl: config.REMOVE_IS_ENTITY_REGISTERED_OWNER_URL,
Expand All @@ -35,15 +35,15 @@ export const postFilterPage = async (req: Request, res: Response, next: NextFunc
logger.debugRequest(req, `${req.method} ${req.route.path}`);
const isSecureRegister = req.body[IsSecureRegisterKey];

setExtraData(req.session, { ...getApplicationData(req.session), [IsSecureRegisterKey]: isSecureRegister });
setExtraData(req.session, { ...(await getApplicationData(req.session)), [IsSecureRegisterKey]: isSecureRegister });

let nextPageUrl: any;
if (isSecureRegister === '1') {
nextPageUrl = isSecureRegisterYes;
} else if (isSecureRegister === '0') {
nextPageUrl = isSecureRegisterNo;
}
if (await isRemoveJourney(req)){
if (await isRemoveJourney(req)) {
nextPageUrl = `${nextPageUrl}${config.JOURNEY_REMOVE_QUERY_PARAM}`;
}
return res.redirect(nextPageUrl);
Expand Down
4 changes: 2 additions & 2 deletions src/utils/who.is.making.filing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@ export const getWhoIsFiling = async (req: Request, res: Response, next: NextFunc
}
};

export const postWhoIsFiling = (req: Request, res: Response, next: NextFunction, agentUrl: string, oeUrl: string) => {
export const postWhoIsFiling = async (req: Request, res: Response, next: NextFunction, agentUrl: string, oeUrl: string) => {
try {
logger.debugRequest(req, `${req.method} ${req.route.path}`);
const whoIsRegistering = req.body[WhoIsRegisteringKey];

setExtraData(req.session, { ...getApplicationData(req.session), [WhoIsRegisteringKey]: whoIsRegistering });
setExtraData(req.session, { ...(await getApplicationData(req.session)), [WhoIsRegisteringKey]: whoIsRegistering });

if (whoIsRegistering === WhoIsRegisteringType.AGENT){
return res.redirect(agentUrl);
Expand Down
12 changes: 6 additions & 6 deletions src/validation/fields/date.validation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -457,20 +457,20 @@ export const trustIndividualCeasedDateValidations = [
...conditionalDateValidations(trusteeCeasedDateValidationsContext),

body("ceasedDate")
.if((value, { req }) => {
.if(async (value, { req }) => {
// check they are on an update or remove journey
// entity_number should have been populated by time they reach trust screens
const appData: ApplicationData = getApplicationData(req.session);
const appData: ApplicationData = await getApplicationData(req.session);
return !!appData.entity_number; // !! = truthy check
})
.if(body("stillInvolved").equals("0"))
.if(body("ceasedDateDay").notEmpty({ ignore_whitespace: true }))
.if(body("ceasedDateMonth").notEmpty({ ignore_whitespace: true }))
.if(body("ceasedDateYear").notEmpty({ ignore_whitespace: true }))
.custom((value, { req }) => {
.custom(async (value, { req }) => {
checkCeasedDateOnOrAfterDateOfBirth(req, ErrorMessages.DATE_BEFORE_BIRTH_DATE_CEASED_TRUSTEE);

checkCeasedDateOnOrAfterTrustCreationDate(req, ErrorMessages.DATE_BEFORE_TRUST_CREATION_DATE_CEASED_TRUSTEE);
await checkCeasedDateOnOrAfterTrustCreationDate(req, ErrorMessages.DATE_BEFORE_TRUST_CREATION_DATE_CEASED_TRUSTEE);

if (req.body["roleWithinTrust"] === RoleWithinTrustType.INTERESTED_PERSON
&& req.body["dateBecameIPDay"]
Expand Down Expand Up @@ -516,9 +516,9 @@ const checkLegalEntityCeasedDateOnOrAfterInterestedPersonStartDate = (req, error
errorMessage);
};

const checkCeasedDateOnOrAfterTrustCreationDate = (req, errorMessage: ErrorMessages) => {
const checkCeasedDateOnOrAfterTrustCreationDate = async (req, errorMessage: ErrorMessages) => {
const trustId = req.params ? req.params[ROUTE_PARAM_TRUST_ID] : undefined;
const appData: ApplicationData = getApplicationData(req.session);
const appData: ApplicationData = await getApplicationData(req.session);
const trust: Trust | undefined = getTrust(appData, trustId);
if (trust) {
checkFirstDateOnOrAfterSecondDate(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ export const trustIndividualBeneficialOwner = [
...usual_residential_service_address_validations(addressErrorMessages as ErrorMessagesRequired),

body("stillInvolved")
.if((value, { req }) => {
const appData: ApplicationData = getApplicationData(req.session);
.if(async (value, { req }) => {
const appData: ApplicationData = await getApplicationData(req.session);
return !!appData.entity_number; // !! = truthy check
})
.not().isEmpty().withMessage(ErrorMessages.TRUSTEE_STILL_INVOLVED),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,8 @@ export const trustLegalEntityBeneficialOwnerValidator = [
await checkIfLessThanTargetValue(req.body.public_register_name.length, req.body.public_register_jurisdiction.length, 160);
}),
body("stillInvolved")
.if((value, { req }) => {
const appData: ApplicationData = getApplicationData(req.session);
.if(async (value, { req }) => {
const appData: ApplicationData = await getApplicationData(req.session);
return !!appData.entity_number; // !! = truthy check
})
.not().isEmpty().withMessage(ErrorMessages.TRUSTEE_STILL_INVOLVED),
Expand Down

0 comments on commit 0ab0482

Please sign in to comment.