Files
pedwfrontend/pages/api/endpoint/getcasebyid_api.js
T
2026-06-29 13:08:06 +00:00

48 lines
1.2 KiB
JavaScript

/**
* @swagger
* /api/endpoint/getcase_api:
* get:
* tags: [Case]
* summary: Not used
* description: Get case
* responses:
* 200:
* description: Success
*/
import { hasOwn } from "../../../components/utils";
import { respondError } from "../middleware/apiResponse";
import { relayGet } from "../middleware/relayForwarding";
export default async function ApiProxy(req, res) {
const incidentID = req.query.incidentID;
if (typeof incidentID !== "string" || incidentID.trim().length === 0) {
return respondError(res, {
status: 400,
code: "INCIDENT_ID_REQUIRED",
message: "incidentID is required"
});
}
const queryUrl = "incidents(" + incidentID + ")";
return relayGet({
queryUrl,
res,
transformData: (data) => {
if (hasOwn(data, "@odata.nextLink") === true) {
const dataStr = JSON.stringify(data["@odata.nextLink"]);
data["@odata.nextLink"] = dataStr.split("/v9.2/")[1];
}
return [data];
},
errorResponse: {
status: 400,
code: "CASE_BY_ID_FETCH_FAILED",
message: "Failed to fetch case by id"
}
});
}