import axios from "axios"; 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 data = JSON.stringify(req.body); const appealObj = req.query.appealObj; const incidentID = req.query.incident; const updateFormCollection = req.query.updateFormCollection; const queryUrl = updateFormCollection + "(" + appealObj + ")"; if ( typeof updateFormCollection === "undefined" || updateFormCollection.length === 0 || typeof appealObj === "undefined" || appealObj.length === 0 || typeof incidentID === "undefined" || incidentID.length === 0 || typeof req.body === "undefined" || req.body === null ) { return respondError(res, { status: 400, code: "MISSING_REQUIRED_QUERY", message: "updateFormCollection, appealObj, incident and body are required" }); } const token = await getToken(); const config = { method: "patch", url: WEBAPI_URL + queryUrl + hashAPIPath(queryUrl), headers: { "OData-MaxVersion": "4.0", "OData-Version": "4.0", "Accept": "application/json", "Prefer": 'odata.include-annotations="*",return=representation', "Authorization": "Bearer " + token.access_token, "Content-Type": "application/json" }, data: data }; //console.log("update case:", data); try { const { data: responseData } = await axios(config); return respondSuccess(res, responseData); } catch (error) { consoleLogger(error); return respondError(res, { status: 400, code: "UPDATE_CASE_FAILED", message: "Failed to update case" }); } }