updated dns and create case queries

This commit is contained in:
robert.bond@test.gov.wales
2021-09-10 16:35:23 +01:00
parent b12b5ef64b
commit 62066285cb
6 changed files with 197 additions and 123 deletions
+124 -85
View File
@@ -1,5 +1,6 @@
import axios from "axios";
import https from "https";
//import {XMLHttpRequest} from 'xmlhttprequest';
process.env["NODE_TLS_REJECT_UNAUTHORIZED"] = 0;
@@ -21,8 +22,35 @@ const agent = new https.Agent({
rejectUnauthorized: false,
});
// export const getAccessToken = () => {
// var ns = "dev-pedw-ns.servicebus.windows.net";
// path = "dev-pedw-hc";
// keyrule = "devpedwnspolicy";
// key = "Ml0Y/S/nfRcmIrHFRkO4jNm2J3iH52TSxPiak7+E1+Y=";
// let accessTokenHeader = {
// headers: {
// "ServiceBusAuthorization": https.createRelayToken(
// https.createRelayHttpsUri(ns, path),
// keyrule,
// key
// ),
// },
// };
// return axios
// .get(ns + path, accessTokenHeader)
// .then((res) => {
// console.log(res.data);
// return res.data;
// })
// .catch((error) => {
// console.log("thiserror", error);
// });
// };
const accessToken =
"eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiIsIng1dCI6IlVXelVaa0U3OEx0NVBGRkJ0LV9seVdoMjdjTSIsImtpZCI6IlVXelVaa0U3OEx0NVBGRkJ0LV9seVdoMjdjTSJ9.eyJhdWQiOiJodHRwczovL2RldmNybTIwMTYubGxjZHQuZ292LndhbGVzLyIsImlzcyI6Imh0dHA6Ly9mcy50ZXN0Lmdvdi53YWxlcy9hZGZzL3NlcnZpY2VzL3RydXN0IiwiaWF0IjoxNjMxMTcwMjI1LCJuYmYiOjE2MzExNzAyMjUsImV4cCI6MTYzMTE5OTAyNSwidXBuIjpbIlJvYmVydC5Cb25kQHRlc3QuZ292LndhbGVzIiwicm9iZXJ0LmJvbmRAdGVzdC5nb3Yud2FsZXMiXSwicHJpbWFyeXNpZCI6IlMtMS01LTIxLTE4MDA4NDIwNzYtMjQ1NTYwNjU5LTQyMTU3NzU0NjktMTY2MjgiLCJ1bmlxdW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HJpbWFyeXNpZCI6IlMtMS01LTIxLTE4MDA4NDIwNzYtMjQ1NTYwNjU5LTQyMTU3NzU0NjktMTY2MjgiLCJ1bmlxdWVfbmFtZSI6IlhNXFxCb25kUiIsImFwcHR5cGUiOiJQdWJsaWMiLCJhcHBpZCI6IjQyN2ZhNzljLWI1ZmMtNDJhZC04M2Q0LTQxMGIwMzk0OGFiNiIsImF1dGhtZXRob2QiOiJodHRwOi8vc2NoZW1hcy5taWNyb3NvZnQuY29tL3dzLzIwMDgvMDYvaWRlbnRpdHkvYXV0aGVudGljYXRpb25tZXRob2Qvd2luZG93cyIsImF1dGhfdGltZSI6IjIwMjEtMDktMTBUMDc6MjY6MzQuMjI0WiIsInZlciI6IjEuMCJ9.XFymIQJVavP-7-8V7LdoYDD4836Z-aSxveMQDD1P3y_9M3Tiy3zINiLxCbSr8JaymFOuLOzWcnNXwh7HHZKY6gDC6tD1ALVKCBXmgTDaoR9j7XAOxSUaRl6ArIecd7o6UcqsHAvfpb5zu-ZIy0KxV9PFRxY4JHF_tfLAeAMnqIBq-yDrNBOlbg4Kd9VuAbAK5lNWp-BiMIzMqZUIrmD9HjwE17SWaEnApCNqTcGZ4h2EqDBWgqKae7B1AzoV_7mfp7CscLUBLGdbM-XsXw3t_AVc0xDHoOMuWfsoMfioJONoMsPqTNUY7VQev1pMrFDEFN-jqP4yqSdNlev6H47SCg";
const crmHeaders = {
withCredentials: true,
@@ -31,21 +59,17 @@ const crmHeaders = {
"OData-MaxVersion": "4.0",
"OData-Version": "4.0",
"Accept": "application/json",
"Prefer": 'odata.include-annotations="*"',
"Prefer": 'odata.include-annotations="*",return=representation',
"Authorization": "Bearer " + accessToken,
},
};
const crmHeadersReturn = {
withCredentials: true,
headers: {
"Content-Type": "application/json; charset=utf-8",
"OData-MaxVersion": "4.0",
"OData-Version": "4.0",
"Accept": "application/json",
"Prefer": "return=representation",
"Access-Control-Allow-Origin": "*",
"Access-Control-Allow-Credentials": "true",
"Content-Type": "application/json",
"Authorization": "Bearer " + accessToken,
},
@@ -269,32 +293,60 @@ export const getPersonalAccount = () => {
});
};
export const createCase = (lpaType, appealType) => {
return axios
.post(
WEBAPI_URL + "incidents",
{
"title": "insertion test case",
"customerid_contact@odata.bind":
"/contacts(f8b454ed-eded-eb11-aac7-00224800be9c)",
},
crmHeadersReturn
)
.then((res) => res.data)
export const createCase = (appealTypeId) => {
appealTypeId = parseInt(appealTypeId);
var data = JSON.stringify({
"title": "insertion test case",
"customerid_contact@odata.bind":
"/contacts(f8b454ed-eded-eb11-aac7-00224800be9c)",
"pinswg_appealcasetype": appealTypeId,
});
var config = {
method: "post",
url: WEBAPI_URL + "incidents",
headers: {
"OData-MaxVersion": "4.0",
"OData-Version": "4.0",
"Accept": "application/json",
"Prefer": "return=representation",
"Content-Type": "application/json",
"Authorization": "Bearer " + accessToken,
},
data: data,
};
console.log(config);
return axios(config)
.then((res) => {
console.log("posted ", res.data);
return res.data;
})
.catch((error) => {
console.log("thi serror", error);
console.log("this serror", error);
});
};
export const updateCase = (incidentID, appealTypeId) => {
return axios
.patch(
WEBAPI_URL + "incidents(" + incidentID + ")",
{
"pinswg_appealtype": appealTypeId,
},
crmHeadersReturn
)
appealTypeId = parseInt(appealTypeId);
var data = JSON.stringify({
"pinswg_appealcasetype": appealTypeId,
});
var config = {
method: "patch",
url: WEBAPI_URL + `incidents(${incidentID})`,
headers: {
"OData-MaxVersion": "4.0",
"OData-Version": "4.0",
"Accept": "application/json",
"Prefer": "return=representation",
"Authorization": "Bearer " + accessToken,
"Content-Type": "application/json",
},
data: data,
};
// console.log(config);
return axios(config)
.then((res) => {
console.log("patched ", res.data);
return res.data;
@@ -304,39 +356,6 @@ export const updateCase = (incidentID, appealTypeId) => {
});
};
// var req = new XMLHttpRequest();
// req.open("GET", Xrm.Page.context.getClientUrl() + "/api/data/v8.2/incidents?$select=_accountid_value,_customerid_value,pinswg_appealcasetype,statuscode,ticketnumber,title&$filter=contains(title, '000')&$count=true", true);
// req.setRequestHeader("OData-MaxVersion", "4.0");
// req.setRequestHeader("OData-Version", "4.0");
// req.setRequestHeader("Accept", "application/json");
// req.setRequestHeader("Content-Type", "application/json; charset=utf-8");
// req.setRequestHeader("Prefer", "odata.include-annotations=\"*\"");
// req.onreadystatechange = function() {
// if (this.readyState === 4) {
// req.onreadystatechange = null;
// if (this.status === 200) {
// var results = JSON.parse(this.response);
// var recordCount = results["@odata.count"];
// for (var i = 0; i < results.value.length; i++) {
// var _accountid_value = results.value[i]["_accountid_value"];
// var _accountid_value_formatted = results.value[i]["_accountid_value@OData.Community.Display.V1.FormattedValue"];
// var _accountid_value_lookuplogicalname = results.value[i]["_accountid_value@Microsoft.Dynamics.CRM.lookuplogicalname"];
// var _customerid_value = results.value[i]["_customerid_value"];
// var _customerid_value_formatted = results.value[i]["_customerid_value@OData.Community.Display.V1.FormattedValue"];
// var _customerid_value_lookuplogicalname = results.value[i]["_customerid_value@Microsoft.Dynamics.CRM.lookuplogicalname"];
// var pinswg_appealcasetype = results.value[i]["pinswg_appealcasetype"];
// var pinswg_appealcasetype_formatted = results.value[i]["pinswg_appealcasetype@OData.Community.Display.V1.FormattedValue"];
// var statuscode = results.value[i]["statuscode"];
// var ticketnumber = results.value[i]["ticketnumber"];
// var title = results.value[i]["title"];
// }
// } else {
// Xrm.Utility.alertDialog(this.statusText);
// }
// }
// };
// req.send();
// //jquery version to get case number from an lpa and an appeal type
// var entity = {};
// entity.caseorigincode = 3;
@@ -369,38 +388,58 @@ export const updateCase = (incidentID, appealTypeId) => {
// });
export const getMyCases = () => {
return axios
.get(BASE_URL + "/api/lookups/myCases", {
httpsAgent: new https.Agent({ rejectUnauthorized: false }),
})
.then((res) => res.data)
.catch((error) => {
console.log("thi serror", error);
});
return (
axios
// .get(BASE_URL + "/api/lookups/myCases", {
// httpsAgent: new https.Agent({ rejectUnauthorized: false }),
// })
.get(
WEBAPI_URL +
"incidents?$select=_accountid_value,_customerid_value,pinswg_appealcasetype,statuscode,ticketnumber,title, _primarycontactid_value&$expand=primarycontactid($select=fullname)&$filter=pinswg_appealcasetype ne null &$count=true",
crmHeaders
)
.then((res) => res.data)
.catch((error) => {
console.log("thi serror", error);
})
);
};
export const getMyRepresentations = () => {
return axios
.get(BASE_URL + "/api/lookups/myRepresentations", {
httpsAgent: new https.Agent({ rejectUnauthorized: false }),
})
.then((res) => res.data)
.catch((error) => {
console.log("thi serror", error);
});
return (
axios
// .get(BASE_URL + "/api/lookups/myRepresentations", {
// httpsAgent: new https.Agent({ rejectUnauthorized: false }),
// })
.get(
WEBAPI_URL +
"incidents?$select=_accountid_value,_customerid_value,pinswg_appealcasetype,statuscode,ticketnumber,title, _primarycontactid_value&$expand=primarycontactid($select=fullname)&$filter=pinswg_appealcasetype ne null &$count=true",
crmHeaders
)
.then((res) => res.data)
.catch((error) => {
console.log("thi serror", error);
})
);
};
export const getWatchedCases = () => {
return axios
return (
axios
.get(BASE_URL + "/api/lookups/watchedCases", {
httpsAgent: new https.Agent({ rejectUnauthorized: false }),
})
.then((res) => res.data)
.catch((error) => {
w;
console.log("thi serror", error);
});
// .get(BASE_URL + "/api/lookups/watchedCases", {
// httpsAgent: new https.Agent({ rejectUnauthorized: false }),
// })
.get(
WEBAPI_URL +
"incidents?$select=_accountid_value,_customerid_value,pinswg_appealcasetype,statuscode,ticketnumber,title, _primarycontactid_value&$expand=primarycontactid($select=fullname)&$filter=pinswg_appealcasetype ne null &$count=true",
crmHeaders
)
.then((res) => res.data)
.catch((error) => {
console.log("this serror", error);
})
);
};
export const getAwaitingSubmission = () => {