60 lines
1.7 KiB
JavaScript
60 lines
1.7 KiB
JavaScript
import { azureHeadersNoOdata } from "../../../actions/core/headers";
|
|
import { respondError } from "../middleware/apiResponse";
|
|
import { relayGet } from "../middleware/relayForwarding";
|
|
|
|
export default async function ApiProxy(req, res) {
|
|
const appealTypeName = req.query.appealTypeName;
|
|
const primaryIdAttribute = req.query.primaryIdAttribute;
|
|
const incidentID = req.query.incidentID;
|
|
|
|
if (
|
|
typeof appealTypeName !== "string" ||
|
|
appealTypeName.trim().length === 0
|
|
) {
|
|
return respondError(res, {
|
|
status: 400,
|
|
code: "APPEAL_TYPE_NAME_REQUIRED",
|
|
message: "appealTypeName is required"
|
|
});
|
|
}
|
|
|
|
if (
|
|
typeof primaryIdAttribute !== "string" ||
|
|
primaryIdAttribute.trim().length === 0
|
|
) {
|
|
return respondError(res, {
|
|
status: 400,
|
|
code: "PRIMARY_ID_ATTRIBUTE_REQUIRED",
|
|
message: "primaryIdAttribute is required"
|
|
});
|
|
}
|
|
|
|
if (typeof incidentID !== "string" || incidentID.trim().length === 0) {
|
|
return respondError(res, {
|
|
status: 400,
|
|
code: "INCIDENT_ID_REQUIRED",
|
|
message: "incidentID is required"
|
|
});
|
|
}
|
|
|
|
const queryUrl =
|
|
appealTypeName +
|
|
"?$filter=_" +
|
|
primaryIdAttribute +
|
|
"s_value eq " +
|
|
incidentID +
|
|
"&$count=true";
|
|
|
|
return relayGet({
|
|
queryUrl,
|
|
res,
|
|
requestOptionsBuilder: (accessToken) =>
|
|
azureHeadersNoOdata(accessToken),
|
|
errorResponse: {
|
|
status: 400,
|
|
code: "BASIC_PART_SAVED_DETAILS_FETCH_FAILED",
|
|
message: "Failed to fetch basic part-saved details"
|
|
}
|
|
});
|
|
}
|