Files
pedwfrontend/pages/case/[ticketnumber].js
T
Robert Bond 9595ad86df Merged PR 2374: addeding domain layer extrraction
# Summary

This PR introduces a **Case Lifecycle Domain Boundary** to centralize lifecycle decision logic and reduce coupling within the appeals application.

The work is **behaviour-preserving** and introduces no intentional changes to business rules, CRM integrations, translations, dashboards, API routes, or user-facing functionality.

## What was added

New lifecycle boundary:

```text
lib/domain/case-lifecycle/
```

Key responsibilities extracted:

- Specialist process normalization
- Appeal type mapping
- Specialist process stage override mapping
- Stage case-type resolution
- Stage catalogue lookup
- Closed-case status recognition
- Lifecycle stage index resolution
- Lifecycle stage status assignment

## Behaviour preserved

Characterization tests were added before each extraction to preserve:

- Appeal type mapping and aliases
- Specialist process handling
- Lifecycle stage progression
- Closed-case handling
- Status assignment (`complete`, `in-progress`, `not-started`)
- Existing ROW behaviour
- Existing `statuscode` lifecycle semantics

Closed-case recognition remains unchanged for:

```text
1000
5
6
846040013
846040059
846040060
```

## Documentation

Added:

```text
lib/domain/case-lifecycle/README.md
```

Documenting:

- Boundary ownership
- Non-goals
- Lifecycle invariants
- Known architectural constraints
- Future extraction roadmap

## Testing

Added lifecycle characterization coverage for:

- Stage wrapper behaviour
- Specialist process normalization
- Appeal type mapping
- Specialist process stage mapping
- Stage case-type resolution
- Stage catalogue lookup
- Progress behaviour
- Closed-case status handling
- Stage index resolution
- Stage status assignment

## Validation

- Lifecycle characterization tests passed
- `npm run lint` passed with no errors

## Out of Scope

No changes to:

- Stage catalogue ownership
- Representation eligibility
- Dashboard calculations
- CRM/OData queries
- API routes
- Redux state
- EN/CY translations
- Event visibility logic

## Risk

**Low risk**

The refactor was delivered through small, characterization-first slices with no functional changes intended.

Related work items: #23527
2026-06-08 09:34:30 +00:00

286 lines
11 KiB
JavaScript

import { getSession } from "next-auth/react";
import useTranslation from "next-translate/useTranslation";
import Head from "next/head";
import { useRouter } from "next/router";
import { connect } from "react-redux";
import { getIP } from "../../actions/core/logger";
import {
getPersonalAccount,
getPortalLogin
} from "../../actions/services/accountService";
import {
getCaseMessage,
getSIPSEvents,
getSIPSMedia
} from "../../actions/services/caseService";
import { getBasicSearch } from "../../actions/services/searchService";
import Breadcrumbs from "../../components/breadcrumbs";
import Case from "../../components/case";
import { normalizeSpecialistProcess } from "../../lib/domain/case-lifecycle";
import CookieBanner from "../../components/cookieBanner";
import Footer from "../../components/footer";
import Header from "../../components/header";
import { getSearchDetails } from "../../components/utils";
import { setAccountDetails } from "../../store/accountDetails/action";
import { setCurrentReference } from "../../store/currentView/action";
import { setSearch } from "../../store/search/action";
import {
setEventDetails,
setSearchDetails,
setSearchResults,
setMediaDetails
} from "../../store/searchOutput/action";
import { wrapper } from "../../store/store";
import ServiceBanner from "../../components/servicebanner";
const CaseHome = (props) => {
const {
footerLinks,
pages,
setSearchResults,
setSearchDetails,
searchResultsObj
} = props;
let { t, lang } = useTranslation();
const router = useRouter();
const { locale } = router;
const { ticketnumber } = router.query;
return (
<div>
<Head>
<title>
Reference:{" "}
{props.searchResultsObj.searchResultsObj.value[0]
.ticketnumber ||
props.currentView.caseReference.currentReference}{" "}
</title>
</Head>
<div id="page_wrapper">
<CookieBanner />
<Header serviceName="Developments of National Significance" />
<div className="govuk-width-container">
<Breadcrumbs slug={ticketnumber} props={props} />
<ServiceBanner />
<Case
props={props}
myCases={props.myCases.myCases}
myCasesDetails={props.myCases.myCasesDetails}
// directSearchResultsObj={
// props.searchResultsObj.searchResultsObj
// }
searchResultsObj={
props.searchResultsObj.searchResultsObj
}
searchDetailsObj={
props.searchResultsObj.searchDetailsObj
}
documentDetailsObj={props.documentDetailsObj}
myRepresentations={
props.myRepresentations.myRepresentations
}
watchedCases={props.watchedCases.watchedCases}
watchedCasesDetails={
props.watchedCases.watchedCasesDetails
}
awaitingSubmission={
props.awaitingSubmission.awaitingSubmission
}
caseReference={
props.searchResultsObj.searchResultsObj.value[0]
.ticketnumber
}
ticketnumber={
props.currentView.caseReference.ticketnumber ||
props.searchResultsObj.searchResultsObj.value[0]
.ticketnumber
}
currentType={props.currentType}
appealTypeID={
props.searchResultsObj.searchResultsObj.value[0]
.pinswg_appealcasetype
}
incidentid={
props.searchResultsObj.searchResultsObj.value[0]
.incidentid
}
representationsObj={
props.searchResultsObj.representationsObj
}
showLoginCheck={props.showLoginCheck}
messagesObj={props.messagesObj}
showFilteredDocs={props.showFilteredDocs}
showMaps={props.showMaps}
eventsObj={props.searchResultsObj.eventsObj}
mediaObj={props.searchResultsObj.mediaObj}
/>
</div>
<Footer
footerLinks={footerLinks}
props={props}
ticketnumber={
props.searchResultsObj.searchResultsObj.value[0]
.ticketnumber
}
/>
</div>
</div>
);
};
export const getServerSideProps = wrapper.getServerSideProps(
(store) => async (ctx) => {
const { query, req, res } = ctx;
getIP(req);
const { cookies } = req;
console.log(cookies);
console.log("the query :", query.ticketnumber);
let thisSession = await getSession(ctx);
let loggedInUser = {};
if (thisSession) {
console.log(" has sesssion.......");
loggedInUser = await getPortalLogin(thisSession.user.email);
loggedInUser = loggedInUser.value[0].contactid;
const accountDetails = await getPersonalAccount(loggedInUser);
store.dispatch(setAccountDetails(accountDetails));
} else {
console.log("not has sesssion.......");
}
let developmentQuery =
query.ticketnumber.indexOf("CAS-") == 0
? query.ticketnumber
: query.ticketnumber.split("-").join(" ");
const searchResultsObj = await getBasicSearch(developmentQuery);
const searchDetailsObj = await getSearchDetails(searchResultsObj);
var eventsObj = {};
var mediaObj = {};
if (searchResultsObj.value[0].pinswg_appealcasetype == 846040002) {
eventsObj = await getSIPSEvents(
searchDetailsObj[0].value[0].pinswg_sipsid
);
store.dispatch(setEventDetails(eventsObj));
}
if (searchResultsObj.value[0].pinswg_appealcasetype == 846040002) {
mediaObj = await getSIPSMedia(searchResultsObj.value[0].incidentid);
store.dispatch(setMediaDetails(mediaObj));
}
//console.log(
// "\n======================================\n",
// searchResultsObj,
// "\n======================================\n"
// );
//console.log(
// "\n======================================\n",
// searchDetailsObj[0],
// "\n======================================\n"
// );
store.dispatch(setSearch(developmentQuery));
console.log(
searchResultsObj["@odata.count"] > 1 ||
searchResultsObj["@odata.count"] < 1
);
if (searchResultsObj["@odata.count"] < 1) {
return {
redirect: {
destination: "/404",
permanent: false
}
};
} else {
if (searchResultsObj["@odata.count"] > 1) {
return {
redirect: {
//destination: "/dns-not-found",
destination: "/404",
permanent: false
}
};
} else {
store.dispatch(setSearchResults(searchResultsObj));
store.dispatch(setSearchDetails(searchDetailsObj));
store.dispatch(
setCurrentReference({
"statuscode": searchResultsObj.value[0].statuscode,
"ticketnumber": searchResultsObj.value[0].ticketnumber,
"currentReference": searchResultsObj.value[0].title,
"currentType": "searchResultsObj",
"incidentid": searchResultsObj.value[0].incidentid,
"appealType":
searchResultsObj.value[0].pinswg_appealcasetype,
"showLoginCheck": true,
"specialistProcess": normalizeSpecialistProcess(
searchDetailsObj[0].value[0]
)
})
);
}
}
//console.log(searchResultsObj);
return {
props: {
searchResultsObj: {
searchResultsObj: searchResultsObj,
searchDetailsObj: searchDetailsObj,
eventsObj: eventsObj,
mediaObj: mediaObj
},
currentType: "directResultsObj",
docsOffline: process.env.DOCAPI_OFFLINE || false,
messagesObj: await getCaseMessage(
searchResultsObj.value[0].incidentid
),
showFilteredDocs: process.env.SHOWFILTERDOCS || false,
showMaps: process.env.SHOWMAPS,
showLoginCheck: process.env.SHOWLOGIN || false
}
};
}
);
const mapStateToProps = (state) => {
return {
accountDetails: state.accountDetails,
currentView: state.currentView,
search: state.search,
//searchResultsObj: state.searchResultsObj,
documentDetailsObj: state.searchResultsObj.documentDetailsObj,
formData: state.formData,
appealType: state.appealType,
form: state.form,
myCases: state.myCases,
watchedCases: state.watchedCases,
myRepresentations: state.myRepresentations,
awaitingSubmission: state.awaitingSubmission
};
};
const mapDispatchToProps = (dispatch) => {
return {
setCurrentReference: (currentReference) => {
dispatch(setCurrentReference(refno));
}
// setSearchResults: (searchResults) => {
// dispatch(setSearchResults(searchResults));
// },
// setSearchDetails: (searchDetails) => {
// dispatch(setSearchDetails(searchDetails));
// },
};
};
export default connect(mapStateToProps, mapDispatchToProps)(CaseHome);