63 lines
1.8 KiB
JavaScript
63 lines
1.8 KiB
JavaScript
/**
|
|
* @swagger
|
|
* /api/endpoint/getcase_api:
|
|
* get:
|
|
* tags: [Case]
|
|
* summary: Not used
|
|
* description: Get case
|
|
* responses:
|
|
* 200:
|
|
* description: Success
|
|
*/
|
|
|
|
import axios from "axios";
|
|
import _ from "lodash";
|
|
import { azureHeaders } from "../../../actions/core/headers";
|
|
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) {
|
|
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"
|
|
});
|
|
}
|
|
|
|
try {
|
|
const token = await getToken();
|
|
const queryUrl =
|
|
"incidents(" +
|
|
incidentID +
|
|
")?$select=ticketnumber,title,pinswg_appealcasetype";
|
|
|
|
const { data } = await axios.get(
|
|
WEBAPI_URL + queryUrl + hashAPIPath(queryUrl),
|
|
azureHeaders(token.access_token)
|
|
);
|
|
|
|
if (_.has(data, "@odata.nextLink") === true) {
|
|
const dataStr = JSON.stringify(data["@odata.nextLink"]);
|
|
data["@odata.nextLink"] = dataStr.split("/v8.2/")[1];
|
|
}
|
|
|
|
return respondSuccess(res, data);
|
|
} catch (error) {
|
|
consoleLogger(error);
|
|
return respondError(res, {
|
|
status: 400,
|
|
code: "CASE_FETCH_FAILED",
|
|
message: "Failed to fetch case"
|
|
});
|
|
}
|
|
}
|