TASK22229: P2-S2 batch 2 migrate portal/representation relay GET endpoints

This commit is contained in:
2026-03-24 07:45:59 +00:00
parent 6edbc431f8
commit fdf95dd0b1
7 changed files with 146 additions and 166 deletions
+35
View File
@@ -801,3 +801,38 @@ Validation:
Follow-ups: Follow-ups:
- Continue P2-S2 with Batch 2 as next dedicated commit on this same branch. - Continue P2-S2 with Batch 2 as next dedicated commit on this same branch.
---
### CL-021: TASK22229 P2-S2 Batch 2 (my-portal + representation relay GET cluster)
date: 2026-03-24
author: Cline
scope: `pages/api/endpoint/{getmycases_api,getmyrepresentations_api,getwatchedcases_api,getawaitingsubmission_api,getrepresentations_api}.js`, `tests/phase21/endpoint-handler-contract.test.cjs`
type: change
rationale: Deliver second P2-S2 commit by migrating the next bounded portal/representation GET endpoint cluster onto shared `relayGet` while preserving route contracts.
impact: Reduced duplicated relay boilerplate and aligned forwarding behavior with no intended response contract changes.
status: completed
Summary:
- Migrated Batch 2 endpoints to `relayGet`:
- `getmycases_api.js` (preserved title mapping transform)
- `getmyrepresentations_api.js`
- `getwatchedcases_api.js` (preserved watched-case projection transform)
- `getawaitingsubmission_api.js` (preserved title mapping transform)
- `getrepresentations_api.js`
- Updated phase21 endpoint contract tests for migrated handlers by mocking `relayGet` in guard/catch test paths.
Validation:
- `node tests/phase21/api-contract-slice1.test.cjs` -> pass
- helper: 4/4
- file-handler: 53/53
- email-handler: 12/12
- endpoint-handler: 152/152
- documents-handler: 3/3
Follow-ups:
- Continue P2-S2 with Batch 3 as the next dedicated commit on this branch.
+18 -31
View File
@@ -17,16 +17,8 @@
* description: Success * description: Success
*/ */
import axios from "axios"; import { respondError } from "../middleware/apiResponse";
import { azureHeaders } from "../../../actions/core/headers"; import { relayGet } from "../middleware/relayForwarding";
import { consoleLogger } from "../../../actions/core/logger";
import { getToken } from "../../../actions/core/token";
import { hashAPIPath } from "../../../actions/core/hash";
import { respondError, respondSuccess } from "../middleware/apiResponse";
const WEBAPI_URL =
process.env.RELAY_ROOT ||
"https://dev-pedw-ns.servicebus.windows.net/dev-pedw-hc/";
export default async function ApiProxy(req, res) { export default async function ApiProxy(req, res) {
const loggedInUserId = req.query.loggedInUserId; const loggedInUserId = req.query.loggedInUserId;
@@ -42,30 +34,25 @@ export default async function ApiProxy(req, res) {
}); });
} }
try { const queryUrl =
const token = await getToken(); "incidents?$select=pinswg_environmentalstatementlocation,modifiedon,description,numberofchildincidents,_accountid_value,_customerid_value,_pinswg_associatedlpa_value,_ownerid_value,pinswg_appealcasetype,statuscode,ticketnumber,title, _primarycontactid_value,pinswg_lpareference,pinswg_appellantlastname,pinswg_appellantfirstname,pinswg_appellantagent,pinswg_agentfirstname,pinswg_agentlastname,pinswg_agentcompanyname&$expand=primarycontactid($select=fullname)&$filter=_customerid_value eq " +
loggedInUserId +
" and servicestage eq 1 and pinswg_appealcasetype ne null&$orderby=createdon desc&$count=true";
const queryUrl = return relayGet({
"incidents?$select=pinswg_environmentalstatementlocation,modifiedon,description,numberofchildincidents,_accountid_value,_customerid_value,_pinswg_associatedlpa_value,_ownerid_value,pinswg_appealcasetype,statuscode,ticketnumber,title, _primarycontactid_value,pinswg_lpareference,pinswg_appellantlastname,pinswg_appellantfirstname,pinswg_appellantagent,pinswg_agentfirstname,pinswg_agentlastname,pinswg_agentcompanyname&$expand=primarycontactid($select=fullname)&$filter=_customerid_value eq " + queryUrl,
loggedInUserId + res,
" and servicestage eq 1 and pinswg_appealcasetype ne null&$orderby=createdon desc&$count=true"; transformData: (data) => {
data.value.forEach(function (element) {
element.pinswg_title = element.title;
});
const { data } = await axios.get( return data;
WEBAPI_URL + queryUrl + hashAPIPath(queryUrl), },
azureHeaders(token.access_token) errorResponse: {
);
data.value.forEach(function (element) {
element.pinswg_title = element.title;
});
return respondSuccess(res, data);
} catch (error) {
consoleLogger(error);
return respondError(res, {
status: 400, status: 400,
code: "AWAITING_SUBMISSION_FETCH_FAILED", code: "AWAITING_SUBMISSION_FETCH_FAILED",
message: "Failed to fetch awaiting submissions" message: "Failed to fetch awaiting submissions"
}); }
} });
} }
+18 -31
View File
@@ -17,16 +17,8 @@
* description: Success * description: Success
*/ */
import axios from "axios"; import { respondError } from "../middleware/apiResponse";
import { azureHeaders } from "../../../actions/core/headers"; import { relayGet } from "../middleware/relayForwarding";
import { consoleLogger } from "../../../actions/core/logger";
import { getToken } from "../../../actions/core/token";
import { hashAPIPath } from "../../../actions/core/hash";
import { respondError, respondSuccess } from "../middleware/apiResponse";
const WEBAPI_URL =
process.env.RELAY_ROOT ||
"https://dev-pedw-ns.servicebus.windows.net/dev-pedw-hc/";
export default async function ApiProxy(req, res) { export default async function ApiProxy(req, res) {
const loggedInUserId = req.query.loggedInUserId; const loggedInUserId = req.query.loggedInUserId;
@@ -42,30 +34,25 @@ export default async function ApiProxy(req, res) {
}); });
} }
try { const queryUrl =
const token = await getToken(); "incidents?$select=pinswg_environmentalstatementlocation,modifiedon,pinswg_publishtoweb,description,numberofchildincidents,_accountid_value,_customerid_value,_pinswg_associatedlpa_value,_ownerid_value,pinswg_appealcasetype,statuscode,ticketnumber,title, _primarycontactid_value,pinswg_lpareference,pinswg_appellantlastname,pinswg_appellantfirstname,pinswg_appellantagent,pinswg_agentfirstname,pinswg_agentlastname,pinswg_agentcompanyname&$expand=primarycontactid($select=fullname)&$filter=_customerid_value eq " +
loggedInUserId +
" and pinswg_appealcasetype ne null&$orderby=createdon desc&$count=true";
const queryUrl = return relayGet({
"incidents?$select=pinswg_environmentalstatementlocation,modifiedon,pinswg_publishtoweb,description,numberofchildincidents,_accountid_value,_customerid_value,_pinswg_associatedlpa_value,_ownerid_value,pinswg_appealcasetype,statuscode,ticketnumber,title, _primarycontactid_value,pinswg_lpareference,pinswg_appellantlastname,pinswg_appellantfirstname,pinswg_appellantagent,pinswg_agentfirstname,pinswg_agentlastname,pinswg_agentcompanyname&$expand=primarycontactid($select=fullname)&$filter=_customerid_value eq " + queryUrl,
loggedInUserId + res,
" and pinswg_appealcasetype ne null&$orderby=createdon desc&$count=true"; transformData: (data) => {
data.value.forEach(function (element) {
element.pinswg_title = element.title;
});
const { data } = await axios.get( return data;
WEBAPI_URL + queryUrl + hashAPIPath(queryUrl), },
azureHeaders(token.access_token) errorResponse: {
);
data.value.forEach(function (element) {
element.pinswg_title = element.title;
});
return respondSuccess(res, data);
} catch (error) {
consoleLogger(error);
return respondError(res, {
status: 400, status: 400,
code: "MY_CASES_FETCH_FAILED", code: "MY_CASES_FETCH_FAILED",
message: "Failed to fetch my cases" message: "Failed to fetch my cases"
}); }
} });
} }
+12 -28
View File
@@ -17,16 +17,8 @@
* description: Success * description: Success
*/ */
import axios from "axios"; import { respondError } from "../middleware/apiResponse";
import { azureHeaders } from "../../../actions/core/headers"; import { relayGet } from "../middleware/relayForwarding";
import { consoleLogger } from "../../../actions/core/logger";
import { getToken } from "../../../actions/core/token";
import { hashAPIPath } from "../../../actions/core/hash";
import { respondError, respondSuccess } from "../middleware/apiResponse";
const WEBAPI_URL =
process.env.RELAY_ROOT ||
"https://dev-pedw-ns.servicebus.windows.net/dev-pedw-hc/";
export default async function ApiProxy(req, res) { export default async function ApiProxy(req, res) {
const loggedInUserId = req.query.loggedInUserId; const loggedInUserId = req.query.loggedInUserId;
@@ -42,26 +34,18 @@ export default async function ApiProxy(req, res) {
}); });
} }
try { const queryUrl =
const token = await getToken(); "pinswg_representationses?$filter= _pinswg_contact_value eq " +
loggedInUserId +
"&$count=true&$orderby=createdon desc";
const queryUrl = return relayGet({
"pinswg_representationses?$filter= _pinswg_contact_value eq " + queryUrl,
loggedInUserId + res,
"&$count=true&$orderby=createdon desc"; errorResponse: {
const { data } = await axios.get(
WEBAPI_URL + queryUrl + hashAPIPath(queryUrl),
azureHeaders(token.access_token)
);
return respondSuccess(res, data);
} catch (error) {
consoleLogger(error);
return respondError(res, {
status: 400, status: 400,
code: "MY_REPRESENTATIONS_FETCH_FAILED", code: "MY_REPRESENTATIONS_FETCH_FAILED",
message: "Failed to fetch my representations" message: "Failed to fetch my representations"
}); }
} });
} }
+12 -28
View File
@@ -17,16 +17,8 @@
* description: Success * description: Success
*/ */
import axios from "axios"; import { respondError } from "../middleware/apiResponse";
import { azureHeaders } from "../../../actions/core/headers"; import { relayGet } from "../middleware/relayForwarding";
import { consoleLogger } from "../../../actions/core/logger";
import { getToken } from "../../../actions/core/token";
import { hashAPIPath } from "../../../actions/core/hash";
import { respondError, respondSuccess } from "../middleware/apiResponse";
const WEBAPI_URL =
process.env.RELAY_ROOT ||
"https://dev-pedw-ns.servicebus.windows.net/dev-pedw-hc/";
export default async function ApiProxy(req, res) { export default async function ApiProxy(req, res) {
const incidentID = req.query.incidentID; const incidentID = req.query.incidentID;
@@ -39,26 +31,18 @@ export default async function ApiProxy(req, res) {
}); });
} }
try { const queryUrl =
const token = await getToken(); "pinswg_representationses?$filter= _pinswg_case_value eq " +
incidentID +
" and pinswg_publishtoweb eq true&$count=true&$orderby=createdon desc";
const queryUrl = return relayGet({
"pinswg_representationses?$filter= _pinswg_case_value eq " + queryUrl,
incidentID + res,
" and pinswg_publishtoweb eq true&$count=true&$orderby=createdon desc"; errorResponse: {
const { data } = await axios.get(
WEBAPI_URL + queryUrl + hashAPIPath(queryUrl),
azureHeaders(token.access_token)
);
return respondSuccess(res, data);
} catch (error) {
consoleLogger(error);
return respondError(res, {
status: 400, status: 400,
code: "REPRESENTATIONS_FETCH_FAILED", code: "REPRESENTATIONS_FETCH_FAILED",
message: "Failed to fetch representations" message: "Failed to fetch representations"
}); }
} });
} }
+36 -48
View File
@@ -17,16 +17,8 @@
* description: Success * description: Success
*/ */
import axios from "axios"; import { respondError } from "../middleware/apiResponse";
import { azureHeaders } from "../../../actions/core/headers"; import { relayGet } from "../middleware/relayForwarding";
import { consoleLogger } from "../../../actions/core/logger";
import { getToken } from "../../../actions/core/token";
import { hashAPIPath } from "../../../actions/core/hash";
import { respondError, respondSuccess } from "../middleware/apiResponse";
const WEBAPI_URL =
process.env.RELAY_ROOT ||
"https://dev-pedw-ns.servicebus.windows.net/dev-pedw-hc/";
export default async function ApiProxy(req, res) { export default async function ApiProxy(req, res) {
const loggedInUserId = req.query.loggedInUserId; const loggedInUserId = req.query.loggedInUserId;
@@ -42,52 +34,48 @@ export default async function ApiProxy(req, res) {
}); });
} }
try { const queryUrl =
const token = await getToken(); "pinswg_watchlists?$filter= _pinswg_contact_value eq " +
loggedInUserId +
"&$select=pinswg_emailnotifications,modifiedon,pinswg_appealcasetype,pinswg_watchlistid,_pinswg_watchedcase_value,statuscode,pinswg_representationsubmitted,pinswg_representationtype&$count=true&$orderby=createdon desc&$expand=pinswg_WatchedCase($select=pinswg_AssociatedLPA)";
const queryUrl = return relayGet({
"pinswg_watchlists?$filter= _pinswg_contact_value eq " + queryUrl,
loggedInUserId + res,
"&$select=pinswg_emailnotifications,modifiedon,pinswg_appealcasetype,pinswg_watchlistid,_pinswg_watchedcase_value,statuscode,pinswg_representationsubmitted,pinswg_representationtype&$count=true&$orderby=createdon desc&$expand=pinswg_WatchedCase($select=pinswg_AssociatedLPA)"; transformData: (data) => {
data.value.forEach(function (element) {
element.ticketnumber = element.pinswg_WatchedCase?.ticketnumber;
element.pinswg_title =
element[
"_pinswg_watchedcase_value@OData.Community.Display.V1.FormattedValue"
];
const { data } = await axios.get(
WEBAPI_URL + queryUrl + hashAPIPath(queryUrl),
azureHeaders(token.access_token)
);
data.value.forEach(function (element) {
element.ticketnumber = element.pinswg_WatchedCase?.ticketnumber;
element.pinswg_title =
element[ element[
"_pinswg_watchedcase_value@OData.Community.Display.V1.FormattedValue"
];
element[
"_pinswg_associatedlpa_value@OData.Community.Display.V1.FormattedValue"
] =
element.pinswg_WatchedCase?.[
"_pinswg_associatedlpa_value@OData.Community.Display.V1.FormattedValue" "_pinswg_associatedlpa_value@OData.Community.Display.V1.FormattedValue"
]; ] =
element._pinswg_associatedlpa_value = element.pinswg_WatchedCase?.[
element.pinswg_WatchedCase?._pinswg_associatedlpa_value; "_pinswg_associatedlpa_value@OData.Community.Display.V1.FormattedValue"
element[ ];
"_ownerid_value@OData.Community.Display.V1.FormattedValue" element._pinswg_associatedlpa_value =
] = element.pinswg_WatchedCase?._pinswg_associatedlpa_value;
element.pinswg_WatchedCase?.[ element[
"_ownerid_value@OData.Community.Display.V1.FormattedValue" "_ownerid_value@OData.Community.Display.V1.FormattedValue"
]; ] =
element._ownerid_value = element.pinswg_WatchedCase?._ownerid_value; element.pinswg_WatchedCase?.[
"_ownerid_value@OData.Community.Display.V1.FormattedValue"
];
element._ownerid_value =
element.pinswg_WatchedCase?._ownerid_value;
delete element.pinswg_WatchedCase; delete element.pinswg_WatchedCase;
}); });
return respondSuccess(res, data); return data;
} catch (error) { },
consoleLogger(error); errorResponse: {
return respondError(res, {
status: 400, status: 400,
code: "WATCHED_CASES_FETCH_FAILED", code: "WATCHED_CASES_FETCH_FAILED",
message: "Failed to fetch watched cases" message: "Failed to fetch watched cases"
}); }
} });
} }
@@ -1555,6 +1555,7 @@ test("getmycases returns LOGGED_IN_USER_ID_REQUIRED when loggedInUserId missing"
const mod = loadModule("pages/api/endpoint/getmycases_api.js", { const mod = loadModule("pages/api/endpoint/getmycases_api.js", {
respondError: respondErrorMock, respondError: respondErrorMock,
respondSuccess: respondSuccessMock, respondSuccess: respondSuccessMock,
relayGet: async () => ({}),
getToken: async () => ({ access_token: "token" }), getToken: async () => ({ access_token: "token" }),
hashAPIPath: () => "&hash=expected", hashAPIPath: () => "&hash=expected",
azureHeaders: () => ({}), azureHeaders: () => ({}),
@@ -1577,6 +1578,8 @@ test("getmycases catch path returns MY_CASES_FETCH_FAILED", async () => {
const mod = loadModule("pages/api/endpoint/getmycases_api.js", { const mod = loadModule("pages/api/endpoint/getmycases_api.js", {
respondError: respondErrorMock, respondError: respondErrorMock,
respondSuccess: respondSuccessMock, respondSuccess: respondSuccessMock,
relayGet: async ({ res, errorResponse }) =>
respondErrorMock(res, errorResponse),
getToken: async () => ({ access_token: "token" }), getToken: async () => ({ access_token: "token" }),
hashAPIPath: () => "&hash=expected", hashAPIPath: () => "&hash=expected",
azureHeaders: () => ({}), azureHeaders: () => ({}),
@@ -1600,6 +1603,7 @@ test("getmyrepresentations returns LOGGED_IN_USER_ID_REQUIRED when loggedInUserI
const mod = loadModule("pages/api/endpoint/getmyrepresentations_api.js", { const mod = loadModule("pages/api/endpoint/getmyrepresentations_api.js", {
respondError: respondErrorMock, respondError: respondErrorMock,
respondSuccess: respondSuccessMock, respondSuccess: respondSuccessMock,
relayGet: async () => ({}),
getToken: async () => ({ access_token: "token" }), getToken: async () => ({ access_token: "token" }),
hashAPIPath: () => "&hash=expected", hashAPIPath: () => "&hash=expected",
azureHeaders: () => ({}), azureHeaders: () => ({}),
@@ -1622,6 +1626,8 @@ test("getmyrepresentations catch path returns MY_REPRESENTATIONS_FETCH_FAILED",
const mod = loadModule("pages/api/endpoint/getmyrepresentations_api.js", { const mod = loadModule("pages/api/endpoint/getmyrepresentations_api.js", {
respondError: respondErrorMock, respondError: respondErrorMock,
respondSuccess: respondSuccessMock, respondSuccess: respondSuccessMock,
relayGet: async ({ res, errorResponse }) =>
respondErrorMock(res, errorResponse),
getToken: async () => ({ access_token: "token" }), getToken: async () => ({ access_token: "token" }),
hashAPIPath: () => "&hash=expected", hashAPIPath: () => "&hash=expected",
azureHeaders: () => ({}), azureHeaders: () => ({}),
@@ -1648,6 +1654,7 @@ test("getwatchedcases returns LOGGED_IN_USER_ID_REQUIRED when loggedInUserId mis
const mod = loadModule("pages/api/endpoint/getwatchedcases_api.js", { const mod = loadModule("pages/api/endpoint/getwatchedcases_api.js", {
respondError: respondErrorMock, respondError: respondErrorMock,
respondSuccess: respondSuccessMock, respondSuccess: respondSuccessMock,
relayGet: async () => ({}),
getToken: async () => ({ access_token: "token" }), getToken: async () => ({ access_token: "token" }),
hashAPIPath: () => "&hash=expected", hashAPIPath: () => "&hash=expected",
azureHeaders: () => ({}), azureHeaders: () => ({}),
@@ -1670,6 +1677,8 @@ test("getwatchedcases catch path returns WATCHED_CASES_FETCH_FAILED", async () =
const mod = loadModule("pages/api/endpoint/getwatchedcases_api.js", { const mod = loadModule("pages/api/endpoint/getwatchedcases_api.js", {
respondError: respondErrorMock, respondError: respondErrorMock,
respondSuccess: respondSuccessMock, respondSuccess: respondSuccessMock,
relayGet: async ({ res, errorResponse }) =>
respondErrorMock(res, errorResponse),
getToken: async () => ({ access_token: "token" }), getToken: async () => ({ access_token: "token" }),
hashAPIPath: () => "&hash=expected", hashAPIPath: () => "&hash=expected",
azureHeaders: () => ({}), azureHeaders: () => ({}),
@@ -1696,6 +1705,7 @@ test("getawaitingsubmission returns LOGGED_IN_USER_ID_REQUIRED when loggedInUser
const mod = loadModule("pages/api/endpoint/getawaitingsubmission_api.js", { const mod = loadModule("pages/api/endpoint/getawaitingsubmission_api.js", {
respondError: respondErrorMock, respondError: respondErrorMock,
respondSuccess: respondSuccessMock, respondSuccess: respondSuccessMock,
relayGet: async () => ({}),
getToken: async () => ({ access_token: "token" }), getToken: async () => ({ access_token: "token" }),
hashAPIPath: () => "&hash=expected", hashAPIPath: () => "&hash=expected",
azureHeaders: () => ({}), azureHeaders: () => ({}),
@@ -1718,6 +1728,8 @@ test("getawaitingsubmission catch path returns AWAITING_SUBMISSION_FETCH_FAILED"
const mod = loadModule("pages/api/endpoint/getawaitingsubmission_api.js", { const mod = loadModule("pages/api/endpoint/getawaitingsubmission_api.js", {
respondError: respondErrorMock, respondError: respondErrorMock,
respondSuccess: respondSuccessMock, respondSuccess: respondSuccessMock,
relayGet: async ({ res, errorResponse }) =>
respondErrorMock(res, errorResponse),
getToken: async () => ({ access_token: "token" }), getToken: async () => ({ access_token: "token" }),
hashAPIPath: () => "&hash=expected", hashAPIPath: () => "&hash=expected",
azureHeaders: () => ({}), azureHeaders: () => ({}),
@@ -3327,6 +3339,7 @@ test("getrepresentations returns INCIDENT_ID_REQUIRED when incidentID missing",
const mod = loadModule("pages/api/endpoint/getrepresentations_api.js", { const mod = loadModule("pages/api/endpoint/getrepresentations_api.js", {
respondError: respondErrorMock, respondError: respondErrorMock,
respondSuccess: respondSuccessMock, respondSuccess: respondSuccessMock,
relayGet: async () => ({}),
getToken: async () => ({ access_token: "token" }), getToken: async () => ({ access_token: "token" }),
hashAPIPath: () => "&hash=expected", hashAPIPath: () => "&hash=expected",
azureHeaders: () => ({}), azureHeaders: () => ({}),
@@ -3346,6 +3359,8 @@ test("getrepresentations catch path returns REPRESENTATIONS_FETCH_FAILED", async
const mod = loadModule("pages/api/endpoint/getrepresentations_api.js", { const mod = loadModule("pages/api/endpoint/getrepresentations_api.js", {
respondError: respondErrorMock, respondError: respondErrorMock,
respondSuccess: respondSuccessMock, respondSuccess: respondSuccessMock,
relayGet: async ({ res, errorResponse }) =>
respondErrorMock(res, errorResponse),
getToken: async () => ({ access_token: "token" }), getToken: async () => ({ access_token: "token" }),
hashAPIPath: () => "&hash=expected", hashAPIPath: () => "&hash=expected",
azureHeaders: () => ({}), azureHeaders: () => ({}),