decopled crm for new appeals - all made on storage

This commit is contained in:
2022-09-28 10:13:36 +01:00
parent bfcd0329c6
commit 745b51839a
15 changed files with 451 additions and 99 deletions
+82
View File
@@ -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;
}
@@ -24,7 +24,6 @@ ApiProxy.get(async (req, res) => {
//if (hashAPIPath(checkquerypath) == "&hash=" + checkHash) {
const blobObj = await getAllProgressBlobs(containerName)
.then((data) => {
//console.log(data);
return downloadAllProgressFiles(containerName, data);
})
.then((data) => {
+56
View File
@@ -0,0 +1,56 @@
import axios from "axios";
import CryptoJS from "crypto-js";
import { getToken, patchCase } from "../../../actions";
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 data = JSON.stringify(req.body);
var appealObj = req.query.appealObj;
var incidentID = req.query.incident;
var updateFormCollection = req.query.updateFormCollection;
var queryUrl = updateFormCollection + "(" + appealObj + ")";
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="*"',
"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) => {
res.status(400);
});
}
+3 -2
View File
@@ -243,7 +243,7 @@ export const getServerSideProps = wrapper.getServerSideProps(
query.casereference
);
// console.log("/////////\nappeal type data:", appealTypeData);
//console.log("/////////\nappeal type data:", appealTypeData);
//
// Removed to make progress from Blob not CRM
@@ -295,9 +295,10 @@ export const getServerSideProps = wrapper.getServerSideProps(
store.dispatch(setCaseReference(caseReference));
store.dispatch(setForm(xmlStr, mandatoryFieldsData, pickListData));
store.dispatch(setAppealType(appealTypeData));
store.dispatch(setFilesForAppeal(blobList));
store.dispatch(setContainerID(thisSession.user.id));
store.dispatch(setFilesForAppeal(blobList));
return {
props: { url: process.env.API_ROOT },
};
+7 -1
View File
@@ -198,6 +198,12 @@ export const getServerSideProps = wrapper.getServerSideProps(
await getAwaitingSubmissionFromBlob(thisSession.user.id),
]);
// console.log(
// "/////////////////////////\n ",
// awaitingSubmissionFromBlob.value,
// awaitingSubmissionFromBlob.case
// );
if (_.has(accountDetails, "errorCode") != false) {
return {
redirect: {
@@ -234,7 +240,7 @@ export const getServerSideProps = wrapper.getServerSideProps(
);
store.dispatch(
setAwaitingSubmissionDetails(awaitingSubmissionDetails)
setAwaitingSubmissionDetails(awaitingSubmissionFromBlob)
);
store.dispatch(setContainerID(thisSession.user.id));
+9 -6
View File
@@ -9,6 +9,7 @@ import xpath from "xpath";
import {
getCase,
getAppealsTypes,
getAppealsTypesForNewAppeal,
getMandatoryFields,
getPickLists,
getFilesFromBlob,
@@ -232,14 +233,12 @@ export const getServerSideProps = wrapper.getServerSideProps(
console.log("logged ident:", loggedInUserIdent, loggedInUserEmail);
const [
caseReferenceData,
appealTypeData,
mandatoryFieldsData,
pickListData,
//blobList,
] = await Promise.all([
await getCase(query.id),
await getAppealsTypes(),
await getAppealsTypesForNewAppeal(),
await getMandatoryFields(query.appealtypes),
await getPickLists(query.appealtypes),
@@ -248,12 +247,16 @@ export const getServerSideProps = wrapper.getServerSideProps(
const blobProgress = await getProgressFromBlob(
loggedInUserIdent,
caseReferenceData.ticketnumber
query.id
);
console.log("anything here", loggedInUser, query.id, caseReferenceData);
console.log("anything here", loggedInUser, query.id, blobProgress);
let caseReference = caseReferenceData; //caseReferenceData.ticketnumber;
let caseReference = {};
caseReference.ticketnumber = query.id;
caseReference.incidentid = query.id;
caseReference.caseDetails = blobProgress; //searchDetailsObj;
var path = require("path");
const configDirectory = path.resolve(process.cwd(), "data/formsxml");