65 lines
2.2 KiB
JavaScript
65 lines
2.2 KiB
JavaScript
import { azureHeaders } from "../../../actions/core/headers";
|
|
import { relayGet } from "../middleware/relayForwarding";
|
|
import { RELAY_POLICY_BOUNDED_READ } from "../middleware/relayPolicyPresets";
|
|
|
|
export default async function ApiProxy(req, res) {
|
|
const { lpaId } = req.query;
|
|
|
|
const filters = ["pinswg_publishtoweb eq true"];
|
|
|
|
if (lpaId) {
|
|
filters.push(`_pinswg_associatedlpa_value eq ${lpaId}`);
|
|
}
|
|
|
|
const queryUrl =
|
|
"incidents?$select=statuscode,pinswg_appealcasetype,_pinswg_associatedlpa_value" +
|
|
`&$filter=${filters.join(" and ")}`;
|
|
|
|
return relayGet({
|
|
queryUrl,
|
|
res,
|
|
requestOptionsBuilder: (accessToken) => azureHeaders(accessToken),
|
|
relayPolicy: RELAY_POLICY_BOUNDED_READ,
|
|
|
|
transformData: (data) => {
|
|
const grouped = (data.value || []).reduce((acc, item) => {
|
|
const key = [
|
|
item.statuscode,
|
|
item.pinswg_appealcasetype,
|
|
item._pinswg_associatedlpa_value || "no-lpa"
|
|
].join("|");
|
|
|
|
if (!acc[key]) {
|
|
acc[key] = {
|
|
statuscode: item.statuscode,
|
|
status: item[
|
|
"statuscode@OData.Community.Display.V1.FormattedValue"
|
|
],
|
|
appealType: item.pinswg_appealcasetype,
|
|
appealTypeName:
|
|
item[
|
|
"pinswg_appealcasetype@OData.Community.Display.V1.FormattedValue"
|
|
],
|
|
lpaId: item._pinswg_associatedlpa_value || null,
|
|
lpaName:
|
|
item[
|
|
"_pinswg_associatedlpa_value@OData.Community.Display.V1.FormattedValue"
|
|
] || null,
|
|
caseCount: 0
|
|
};
|
|
}
|
|
|
|
acc[key].caseCount += 1;
|
|
return acc;
|
|
}, {});
|
|
|
|
return Object.values(grouped);
|
|
},
|
|
errorResponse: {
|
|
status: 400,
|
|
code: "STATUS_COUNTS_FETCH_FAILED",
|
|
message: "Failed to fetch status counts"
|
|
}
|
|
});
|
|
}
|