generated from hmcts/expressjs-template
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
CIV-14636 CUI R2 - View and Response link not working intermittently (#…
…4196) * CIV-14636 test pr * CIV-14636 clearing cache after fee breakup controller * CIV-14363 reverted temp change * CIV-14636 Added redis logic for claimantIntent guard * CIV-14636 Removed redis cache in claimant Intent Guard * CIV-14636 Updated CLaimantIntent guard for redis cache * CIV-14636 fixed unit tests * CIV-14636 Fixed formatting issue --------- Co-authored-by: Paul Pearson <[email protected]> Co-authored-by: Raja Mani <[email protected]>
- Loading branch information
1 parent
f7cf956
commit d79ea3d
Showing
4 changed files
with
68 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,34 @@ | ||
import { NextFunction, Request, Response } from 'express'; | ||
import { Claim } from '../../common/models/claim'; | ||
import { NextFunction,Request, Response } from 'express'; | ||
import { constructResponseUrlWithIdParams } from '../../common/utils/urlFormatter'; | ||
import { DASHBOARD_CLAIMANT_URL } from '../../routes/urls'; | ||
import { getClaimById } from 'modules/utilityService'; | ||
export const claimantIntentGuard = ( | ||
req: Request, | ||
res: Response, | ||
next: NextFunction, | ||
) => { | ||
(async () => { | ||
try { | ||
const caseData: Claim = await getClaimById(req.params.id, req, true); | ||
if (caseData.isClaimantIntentionPending() || req.originalUrl.includes('claimant-response/confirmation')) { | ||
next(); | ||
} else { | ||
res.redirect( | ||
constructResponseUrlWithIdParams( | ||
req.params.id, | ||
DASHBOARD_CLAIMANT_URL, | ||
), | ||
); | ||
} | ||
} catch (error) { | ||
next(error); | ||
import {deleteDraftClaimFromStore, generateRedisKey, getCaseDataFromStore } from 'modules/draft-store/draftStoreService'; | ||
import { AppRequest } from 'common/models/AppRequest'; | ||
import { Claim } from 'common/models/claim'; | ||
|
||
export const claimantIntentGuard = (async (req: Request, res: Response, next: NextFunction) => { | ||
try { | ||
const redisClaimId = generateRedisKey(req as AppRequest); | ||
const caseStoreData: Claim = await getCaseDataFromStore(redisClaimId, true); | ||
|
||
// Delete cache from redis if case state is not AWAITING_APPLICANT_INTENTION. | ||
// Giving a chance to reload data from ccd database. | ||
if(caseStoreData && !caseStoreData.isEmpty() && !caseStoreData.isClaimantIntentionPending()) { | ||
await deleteDraftClaimFromStore(redisClaimId); | ||
} | ||
})(); | ||
}; | ||
|
||
const caseData = await getClaimById(req.params.id, req, true); | ||
if (caseData.isClaimantIntentionPending() || req.originalUrl.includes('claimant-response/confirmation')) { | ||
next(); | ||
} else { | ||
res.redirect( | ||
constructResponseUrlWithIdParams( | ||
req.params.id, | ||
DASHBOARD_CLAIMANT_URL, | ||
), | ||
); | ||
} | ||
} catch (error) { | ||
next(error); | ||
} | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters