59 lines
1.8 KiB
JavaScript
59 lines
1.8 KiB
JavaScript
import axios from "axios";
|
|
import CryptoJS from "crypto-js";
|
|
import { consoleLogger } from "../../../actions/core/logger";
|
|
import { getToken } from "../../../actions/core/token";
|
|
import { hashAPIPath } from "../../../actions/core/hash";
|
|
|
|
const WEBAPI_URL =
|
|
process.env.RELAY_ROOT ||
|
|
"https://dev-pedw-ns.servicebus.windows.net/dev-pedw-hc/";
|
|
|
|
export default async function ApiProxy(req, res) {
|
|
var data = JSON.stringify(req.body);
|
|
var appealObj = req.query.appealObj;
|
|
var incidentID = req.query.incident;
|
|
|
|
var updateFormCollection = req.query.updateFormCollection;
|
|
var 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 res.status(400).json();
|
|
}
|
|
|
|
var token = await getToken();
|
|
|
|
var 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);
|
|
|
|
return axios(config)
|
|
.then(({ data }) => {
|
|
res.status(200).json(data);
|
|
})
|
|
.catch((error) => {
|
|
consoleLogger(error);
|
|
res.status(400).json(error);
|
|
});
|
|
}
|