refactor(case): normalize route composition with fileRouteBuilder

This commit is contained in:
2026-03-25 11:49:19 +00:00
parent ae64ee6c2b
commit 05f26ff12c
3 changed files with 164 additions and 89 deletions
+97 -89
View File
@@ -2,45 +2,54 @@ import { BASE_URL } from "../core/env";
import { consoleLogger } from "../core/logger"; import { consoleLogger } from "../core/logger";
import { logAndReturnResponse } from "./httpServiceUtils"; import { logAndReturnResponse } from "./httpServiceUtils";
import { getJson, requestJson } from "../clients/endpointClient"; import { getJson, requestJson } from "../clients/endpointClient";
import { buildFileQuery, withBaseUrl } from "../clients/fileRouteBuilder";
export const getCaseMessage = (searchString) => { export const getCaseMessage = (searchString) => {
return getJson( const route = buildFileQuery("/api/endpoint/getcasemessage_api", {
BASE_URL + "/api/endpoint/getcasemessage_api?id=" + searchString id: searchString
).catch(logAndReturnResponse); });
return getJson(withBaseUrl(BASE_URL, route)).catch(logAndReturnResponse);
}; };
export const getIncidentbyID = (searchString) => { export const getIncidentbyID = (searchString) => {
return getJson( const route = buildFileQuery("/api/endpoint/getincidentbyid_api", {
BASE_URL + searchString
"/api/endpoint/getincidentbyid_api?searchString=" + });
searchString
).catch(logAndReturnResponse); return getJson(withBaseUrl(BASE_URL, route)).catch(logAndReturnResponse);
}; };
export const getIsPublishedbyID = (searchString) => { export const getIsPublishedbyID = (searchString) => {
return getJson( const route = buildFileQuery("/api/endpoint/getispublishedbyid_api", {
"/api/endpoint/getispublishedbyid_api?searchString=" + searchString searchString
).catch(logAndReturnResponse); });
return getJson(route).catch(logAndReturnResponse);
}; };
export const getPartSavedAppeal = (searchString) => { export const getPartSavedAppeal = (searchString) => {
return getJson( const route = buildFileQuery("/api/endpoint/getpartsavedappeal_api", {
BASE_URL + searchString
"/api/endpoint/getpartsavedappeal_api?searchString=" + });
searchString
).catch(logAndReturnResponse); return getJson(withBaseUrl(BASE_URL, route)).catch(logAndReturnResponse);
}; };
export const getSIPSEvents = async (caseid) => { export const getSIPSEvents = async (caseid) => {
return getJson( const route = buildFileQuery("/api/endpoint/getsipsevents_api", {
BASE_URL + "/api/endpoint/getsipsevents_api?caseid=" + caseid caseid
).catch(logAndReturnResponse); });
return getJson(withBaseUrl(BASE_URL, route)).catch(logAndReturnResponse);
}; };
export const getSIPSMedia = async (caseid) => { export const getSIPSMedia = async (caseid) => {
return getJson( const route = buildFileQuery("/api/endpoint/getsipsmedia_api", {
BASE_URL + "/api/endpoint/getsipsmedia_api?caseid=" + caseid caseid
).catch(logAndReturnResponse); });
return getJson(withBaseUrl(BASE_URL, route)).catch(logAndReturnResponse);
}; };
export const getAppealID = ( export const getAppealID = (
@@ -48,14 +57,13 @@ export const getAppealID = (
updateFormCollection, updateFormCollection,
primaryAttribute primaryAttribute
) => { ) => {
return getJson( const route = buildFileQuery("/api/endpoint/getappealid_api", {
"/api/endpoint/getappealid_api?updateFormCollection=" + updateFormCollection,
updateFormCollection + primaryAttribute,
"&primaryAttribute=" + caseReference
primaryAttribute + });
"&caseReference=" +
caseReference return getJson(route)
)
.then((data) => { .then((data) => {
const result = Object.entries(data.value[0]).filter( const result = Object.entries(data.value[0]).filter(
([key]) => !key.startsWith("_") ([key]) => !key.startsWith("_")
@@ -79,19 +87,16 @@ export const createNewCase = (
var data = createBody; var data = createBody;
var queryUrl = var queryUrl = buildFileQuery("/api/endpoint/createcase_api", {
"/api/endpoint/createcase_api?appealTypeId=" + appealTypeId,
appealTypeId + lpaID,
"&lpaID=" + contactid,
lpaID + containername: containerName
"&contactid=" + });
contactid +
"&containername=" +
containerName;
var config = { var config = {
method: "post", method: "post",
url: BASE_URL + queryUrl, url: withBaseUrl(BASE_URL, queryUrl),
data: data data: data
}; };
@@ -115,15 +120,12 @@ export const createNewCaseBlob = (
data.pinswg_lpaname = lpaName; data.pinswg_lpaname = lpaName;
data.createdon = new Date(); data.createdon = new Date();
var queryUrl = var queryUrl = buildFileQuery("/api/file/createcase_api", {
"/api/file/createcase_api?appealTypeId=" + appealTypeId,
appealTypeId + lpaID,
"&lpaID=" + contactid,
lpaID + containername: containerName
"&contactid=" + });
contactid +
"&containername=" +
containerName;
var config = { var config = {
method: "post", method: "post",
@@ -151,11 +153,10 @@ export const updateCase = async (
primaryAttribute primaryAttribute
); );
var queryUrl = var queryUrl = buildFileQuery("/api/endpoint/updatecase_api", {
"/api/endpoint/updatecase_api?updateFormCollection=" + updateFormCollection,
updateFormCollection + appealObj
"&appealObj=" + });
appealObj;
var config = { var config = {
method: "post", method: "post",
@@ -183,11 +184,10 @@ export const updateCaseBlob = async (
primaryAttribute primaryAttribute
); );
var queryUrl = var queryUrl = buildFileQuery("/api/file/updatecase_api", {
"/api/file/updatecase_api?updateFormCollection=" + updateFormCollection,
updateFormCollection + appealObj
"&appealObj=" + });
appealObj;
var config = { var config = {
method: "post", method: "post",
@@ -201,68 +201,76 @@ export const updateCaseBlob = async (
}; };
export const patchCase = async (incidentid) => { export const patchCase = async (incidentid) => {
var queryUrl = "/api/endpoint/patchcase_api?incidentid=" + incidentid; var queryUrl = buildFileQuery("/api/endpoint/patchcase_api", {
incidentid
});
return getJson(queryUrl).catch((error) => { return getJson(queryUrl).catch((error) => {
//console.log("this error:", error); //console.log("this error:", error);
}); });
}; };
export const getCase = (incidentID) => { export const getCase = (incidentID) => {
return getJson( const route = buildFileQuery("/api/endpoint/getcase_api", {
BASE_URL + "/api/endpoint/getcase_api?incidentID=" + incidentID incidentID
).catch((error) => { });
return getJson(withBaseUrl(BASE_URL, route)).catch((error) => {
consoleLogger(error); consoleLogger(error);
}); });
}; };
export const getCaseByID = (incidentID) => { export const getCaseByID = (incidentID) => {
return getJson( const route = buildFileQuery("/api/endpoint/getcasebyid_api", {
BASE_URL + "/api/endpoint/getcasebyid_api?incidentID=" + incidentID incidentID
).catch((error) => { });
return getJson(withBaseUrl(BASE_URL, route)).catch((error) => {
consoleLogger(error); consoleLogger(error);
}); });
}; };
export const getAppealPDFDocs = (incidentID) => { export const getAppealPDFDocs = (incidentID) => {
return getJson( const route = buildFileQuery("/api/endpoint/getappealpdfdocuments_api", {
BASE_URL + incidentid: incidentID
"/api/endpoint/getappealpdfdocuments_api?incidentid=" + });
incidentID
).catch((error) => { return getJson(withBaseUrl(BASE_URL, route)).catch((error) => {
consoleLogger(error); consoleLogger(error);
}); });
}; };
export const getAppealPDFDocument = async (incidentid) => { export const getAppealPDFDocument = async (incidentid) => {
return getJson( const route = buildFileQuery("/api/endpoint/getappealpdfdocuments_api", {
BASE_URL + incidentid
"/api/endpoint/getappealpdfdocuments_api?incidentid=" + });
incidentid
).catch((error) => { return getJson(withBaseUrl(BASE_URL, route)).catch((error) => {
consoleLogger(error); consoleLogger(error);
return error.response; return error.response;
}); });
}; };
export const getPortalModuleDetails = async (appealType, caseReference) => { export const getPortalModuleDetails = async (appealType, caseReference) => {
return getJson( const route = buildFileQuery("/api/endpoint/getportalmoduledetails_api", {
BASE_URL + appealType,
"/api/endpoint/getportalmoduledetails_api?appealType=" + caseReference: encodeURI(caseReference)
appealType + });
"&caseReference=" +
encodeURI(caseReference) return getJson(withBaseUrl(BASE_URL, route)).catch((error) => {
).catch((error) => {
consoleLogger(error); consoleLogger(error);
}); });
}; };
export const getPortalModuleDetailsProxy = (appealType, caseReference) => { export const getPortalModuleDetailsProxy = (appealType, caseReference) => {
return getJson( const route = buildFileQuery(
"/api/endpoint/getportalmoduledetailsproxy_api?appealType=" + "/api/endpoint/getportalmoduledetailsproxy_api",
appealType + {
"&caseReference=" + appealType,
caseReference.replace(/\'/g, "''") caseReference: caseReference.replace(/\'/g, "''")
).catch((error) => { }
);
return getJson(route).catch((error) => {
consoleLogger(error); consoleLogger(error);
}); });
}; };
+43
View File
@@ -2559,3 +2559,46 @@ Validation:
Follow-ups: Follow-ups:
- Optional next widened slice: apply the same query-normalization helpers in `caseDirectService` and add dedicated phase22 behavioral assertions for `portalDirectService` route-building/signing composition. - Optional next widened slice: apply the same query-normalization helpers in `caseDirectService` and add dedicated phase22 behavioral assertions for `portalDirectService` route-building/signing composition.
---
### CL-072: TASK22260 next widened cross-module slice — case service query normalization via fileRouteBuilder
date: 2026-03-25
author: Cline
scope: `actions/services/caseDirectService.js`, `tests/phase6/service-behaviour.test.cjs`
type: change
rationale: Continue widened cross-module rollout by applying shared query/route composition helpers to `caseDirectService`, reducing repeated string concatenation and aligning route construction style with document/portal services.
impact: Improves maintainability and consistency in case service URL/query composition while preserving existing runtime behavior and error contracts.
status: completed
Summary:
- Refactored `actions/services/caseDirectService.js` to use `fileRouteBuilder` helpers:
- `buildFileQuery`
- `withBaseUrl`
- Normalized route composition for read and write helpers, including:
- case retrieval/search flows (`getCaseMessage`, `getIncidentbyID`, `getIsPublishedbyID`, `getPartSavedAppeal`, `getSIPSEvents`, `getSIPSMedia`)
- appeal resolution/update/create flows (`getAppealID`, `createNewCase`, `createNewCaseBlob`, `updateCase`, `updateCaseBlob`, `patchCase`)
- case/detail/document/module reads (`getCase`, `getCaseByID`, `getAppealPDFDocs`, `getAppealPDFDocument`, `getPortalModuleDetails`, `getPortalModuleDetailsProxy`)
- Preserved existing contracts:
- BASE_URL usage patterns where previously applied
- method/payload semantics for `requestJson` paths
- catch-path logging and return behavior (`logAndReturnResponse`, `consoleLogger`, `error.response` paths)
- Expanded phase6 behavioural coverage with a focused assertion for case route composition:
- `case/getPortalModuleDetails composes BASE_URL route with encoded case reference`
Validation:
- `node tests/phase6/service-behaviour.test.cjs` -> pass (9/9)
- `node tests/phase7/service-behaviour.test.cjs` -> pass (13/13)
- `node tests/phase22/index.test.cjs` -> pass
- core-token: 2/2
- client-utils: 6/6
- file-client: 4/4
- phase22 combined: pass
- `npm run lint` -> warnings only (pre-existing `react-hooks/exhaustive-deps`; no new lint errors)
Follow-ups:
- Optional next widened slice: add a focused phase22 behavioral suite for `caseDirectService` and normalize any remaining specialized encoding usage behind explicit helper options where appropriate.
+24
View File
@@ -138,6 +138,30 @@ test("case/getCaseMessage returns error.response on failure", async () => {
assert.strictEqual(logger.calls.length, 1); assert.strictEqual(logger.calls.length, 1);
}); });
test("case/getPortalModuleDetails composes BASE_URL route with encoded case reference", async () => {
const axios = createAxiosMock();
const logger = createLoggerMock();
axios.getHandler = async () => ({ data: { value: [] } });
const caseService = loadServiceModule("caseDirectService.js", {
axios,
BASE_URL: "http://example.local",
consoleLogger: logger.consoleLogger
});
const result = await caseService.getPortalModuleDetails(
"appeal",
"REF A/B"
);
assert.deepStrictEqual(normalize(result), { value: [] });
assert.strictEqual(
axios.calls[0].url,
"http://example.local/api/endpoint/getportalmoduledetails_api?appealType=appeal&caseReference=REF%20A/B"
);
});
test("admin/getNewAppealsPage returns res.data on success", async () => { test("admin/getNewAppealsPage returns res.data on success", async () => {
const axios = createAxiosMock(); const axios = createAxiosMock();
const logger = createLoggerMock(); const logger = createLoggerMock();