decopled crm for new appeals - all made on storage
This commit is contained in:
@@ -0,0 +1,82 @@
|
||||
import axios from "axios";
|
||||
import CryptoJS from "crypto-js";
|
||||
import _ from "lodash";
|
||||
import { getToken, azureHeadersPaged, consoleLogger } from "../../../actions";
|
||||
import { getCaseBlob, createBlob } from "../../../actions/azurestorage";
|
||||
import { getTempCaseRef } from "../../../components/utils";
|
||||
import { v4 as uuidv4 } from "uuid";
|
||||
|
||||
const WORDKEY = process.env.HASHKEY;
|
||||
|
||||
const WEBAPI_URL =
|
||||
process.env.RELAY_ROOT ||
|
||||
"https://dev-pedw-ns.servicebus.windows.net/dev-pedw-hc/";
|
||||
|
||||
const hashAPIPath = (queryPath) => {
|
||||
var hashlink = CryptoJS.HmacSHA256(
|
||||
queryPath,
|
||||
CryptoJS.enc.Hex.parse(WORDKEY)
|
||||
);
|
||||
hashlink = hashlink.toString(CryptoJS.enc.Hex);
|
||||
|
||||
//return "&hash=" + hashlink;
|
||||
|
||||
return (queryPath.indexOf("?") > -1 ? "&hash=" : "?hash=") + hashlink;
|
||||
};
|
||||
|
||||
export default async function ApiProxy(req, res) {
|
||||
var createCaseBody = req.body;
|
||||
var contactid = req.query.contactid;
|
||||
var appealTypeId = req.query.appealTypeId;
|
||||
var containerName = req.query.containername;
|
||||
var lpaID = req.query.lpaID;
|
||||
var queryUrl = "incidents";
|
||||
var token = await getToken();
|
||||
var tempCaseRef = getTempCaseRef();
|
||||
|
||||
var data = {
|
||||
"title": tempCaseRef,
|
||||
"ticketnumber": tempCaseRef,
|
||||
"incidentid": uuidv4(),
|
||||
"statecode": 0,
|
||||
"statuscode": 1,
|
||||
"caseorigincode": 3,
|
||||
"servicestage": 1,
|
||||
"customerid_contact@odata.bind": "/contacts(" + contactid + ")",
|
||||
"pinswg_appealcasetype": appealTypeId,
|
||||
"pinswg_AssociatedLPA@odata.bind": "/accounts(" + lpaID + ")",
|
||||
};
|
||||
var newData = Object.assign(data, createCaseBody);
|
||||
|
||||
delete newData.lpaTypes;
|
||||
delete newData.appealTypes;
|
||||
|
||||
console.log("/////Create Case:\n", newData, "\n//////////////");
|
||||
|
||||
var newAppealObj = {
|
||||
"pinswg_name": tempCaseRef,
|
||||
"pinswg_appealcasetype": appealTypeId,
|
||||
"_pinswg_associatedlpa_value": lpaID,
|
||||
};
|
||||
|
||||
// var config = {
|
||||
// method: "post",
|
||||
// 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: JSON.stringify(newData),
|
||||
// };
|
||||
var apiResponse = _.isEmpty(req.query)
|
||||
? res.status(400).json()
|
||||
: (getCaseBlob(containerName, tempCaseRef, newData),
|
||||
createBlob(JSON.stringify(newAppealObj), containerName),
|
||||
res.status(200).json(newData));
|
||||
|
||||
return apiResponse;
|
||||
}
|
||||
Reference in New Issue
Block a user