create incident record in new appeal

This commit is contained in:
robert.bond@test.gov.wales
2021-09-09 12:29:18 +01:00
parent 2825ab5a7d
commit b12b5ef64b
9 changed files with 161 additions and 116 deletions
+81 -92
View File
@@ -13,13 +13,17 @@ if (process.browser) {
BASE_URL = process.env.API_ROOT || `http://localhost:${port}`;
}
const WEBAPI_URL = "https://devcrm2016.llcdt.gov.wales/DVPINS";
const API_PATH = "/api/data/v8.2/";
const WEBAPI_URL = "https://devcrm2016.llcdt.gov.wales/DVPINS" + API_PATH;
const agent = new https.Agent({
rejectUnauthorized: false,
});
const accessToken =
"eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiIsIng1dCI6IlVXelVaa0U3OEx0NVBGRkJ0LV9seVdoMjdjTSIsImtpZCI6IlVXelVaa0U3OEx0NVBGRkJ0LV9seVdoMjdjTSJ9.eyJhdWQiOiJodHRwczovL2RldmNybTIwMTYubGxjZHQuZ292LndhbGVzLyIsImlzcyI6Imh0dHA6Ly9mcy50ZXN0Lmdvdi53YWxlcy9hZGZzL3NlcnZpY2VzL3RydXN0IiwiaWF0IjoxNjMxMTcwMjI1LCJuYmYiOjE2MzExNzAyMjUsImV4cCI6MTYzMTE5OTAyNSwidXBuIjpbIlJvYmVydC5Cb25kQHRlc3QuZ292LndhbGVzIiwicm9iZXJ0LmJvbmRAdGVzdC5nb3Yud2FsZXMiXSwicHJpbWFyeXNpZCI6IlMtMS01LTIxLTE4MDA4NDIwNzYtMjQ1NTYwNjU5LTQyMTU3NzU0NjktMTY2MjgiLCJ1bmlxdWVfbmFtZSI6IlhNXFxCb25kUiIsImFwcHR5cGUiOiJQdWJsaWMiLCJhcHBpZCI6IjQyN2ZhNzljLWI1ZmMtNDJhZC04M2Q0LTQxMGIwMzk0OGFiNiIsImF1dGhtZXRob2QiOiJodHRwOi8vc2NoZW1hcy5taWNyb3NvZnQuY29tL3dzLzIwMDgvMDYvaWRlbnRpdHkvYXV0aGVudGljYXRpb25tZXRob2Qvd2luZG93cyIsImF1dGhfdGltZSI6IjIwMjEtMDktMDlUMDY6NTA6MjIuMTgzWiIsInZlciI6IjEuMCJ9.jds1ILVmVonh1g_KDDzFHZV7_iFpR4GZ6m_uw7YDQpQLXQlFXkPLf-Fan1h61Jl78ZmsBnhPKREvqALQ13tcMPPDg4SK5i6BYI7Jw8eKnqCjNb_mFAnnSCL0NeqZY4JV-HYzgY5tpvuCWgpjL2v_5BKOtU9mRL_700D7Fjt_R6nlI89dOKy3iT88lUxPostTVEC1nBxvh1AjjACG6103ymtRBtRy2ONowk4PClhCO3ZWwnVg1kb4GmXqhKNsXBvEscuZQuAzvawwTIXMvjwUBFSu4fsGdxxjfdsXVGACPdcUn7FekJIzaDtS2I_DvzrWLn9B1BDyBEctUqoVWOWqBw";
const crmHeaders = {
withCredentials: true,
headers: {
@@ -28,8 +32,22 @@ const crmHeaders = {
"OData-Version": "4.0",
"Accept": "application/json",
"Prefer": 'odata.include-annotations="*"',
"Authorization":
"Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiIsIng1dCI6IlVXelVaa0U3OEx0NVBGRkJ0LV9seVdoMjdjTSIsImtpZCI6IlVXelVaa0U3OEx0NVBGRkJ0LV9seVdoMjdjTSJ9.eyJhdWQiOiJodHRwczovL2RldmNybTIwMTYubGxjZHQuZ292LndhbGVzLyIsImlzcyI6Imh0dHA6Ly9mcy50ZXN0Lmdvdi53YWxlcy9hZGZzL3NlcnZpY2VzL3RydXN0IiwiaWF0IjoxNjMxMDgwNTk3LCJuYmYiOjE2MzEwODA1OTcsImV4cCI6MTYzMTEwOTM5NywidXBuIjpbIlJvYmVydC5Cb25kQHRlc3QuZ292LndhbGVzIiwicm9iZXJ0LmJvbmRAdGVzdC5nb3Yud2FsZXMiXSwicHJpbWFyeXNpZCI6IlMtMS01LTIxLTE4MDA4NDIwNzYtMjQ1NTYwNjU5LTQyMTU3NzU0NjktMTY2MjgiLCJ1bmlxdWVfbmFtZSI6IlhNXFxCb25kUiIsImFwcHR5cGUiOiJQdWJsaWMiLCJhcHBpZCI6IjQyN2ZhNzljLWI1ZmMtNDJhZC04M2Q0LTQxMGIwMzk0OGFiNiIsImF1dGhtZXRob2QiOiJodHRwOi8vc2NoZW1hcy5taWNyb3NvZnQuY29tL3dzLzIwMDgvMDYvaWRlbnRpdHkvYXV0aGVudGljYXRpb25tZXRob2Qvd2luZG93cyIsImF1dGhfdGltZSI6IjIwMjEtMDktMDhUMDU6NTY6MzcuMjg1WiIsInZlciI6IjEuMCJ9.bsZhsbeQtJpLxxe70nePUnT-vokKDVUZh3s17w34TAWlWERAj4KxxcAJvhTACz9BJqz7YXTBsqPu2Kq10f_g9FibIgqQZEMiFM4nKFbgALRXjdEtP6ptpqLBvbW2ECCHSnf_IpClhmr0d_a1nv-MQ62YmKyztcEvNBd7IC1NZsWrAf2jLYg_ROOxjtAlK3itfSqGazkvKdgYYtbC-Al6hjn5y-3E0lfq2H8ZZdVFa9XcDOss5rxSeJBkJK6Ezczov5FXHhN9oATTiA0khRpcnqfXbhW2H8w5PYqyZGa7_LMDAdmeCgBxAva874jadjIN2Fjfq9Bo6V1v6OvbXBgAAg",
"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,
},
};
@@ -37,7 +55,6 @@ export const getBasicSearch = (searchString) => {
return axios
.get(
WEBAPI_URL +
API_PATH +
"incidents?$select=_accountid_value,_customerid_value,pinswg_appealcasetype,statuscode,ticketnumber,title, _primarycontactid_value&$expand=primarycontactid($select=fullname)&$filter=contains(title, '" +
searchString +
"') and pinswg_appealcasetype ne null &$count=true",
@@ -53,7 +70,6 @@ export const getBasicSearchDetails = (appealType, caseReference) => {
return axios
.get(
WEBAPI_URL +
API_PATH +
appealType +
"?$filter=pinswg_name eq '" +
caseReference +
@@ -69,40 +85,24 @@ export const getBasicSearchDetails = (appealType, caseReference) => {
export const getFormData = (whichForm) => {
console.log("got to axios", whichForm);
console.log("api_root: ", BASE_URL);
return (
axios
//.get("api/appealforms/pinswg_dns", {
//.get("api/appealforms/pinswg_planningobligationappeals106", {
//.get("api/appealforms/pinswg_planningconditionss73s79", {
//.get("api/appealforms/pinswg_row", {
//.get("api/appealforms/pinswg_transportandworkact", {
//.get("api/appealforms/pinswg_harbourrevisionorder", {
//.get("api/appealforms/pinswg_planningappeals78", {
//.get(api/appealforms/pinswg_householderappealhas", {
// .get(BASE_URL + "/api/appealforms/pinswg_" + whichForm, {
// httpsAgent: new https.Agent({ rejectUnauthorized: false }),
// })
.get(
WEBAPI_URL +
API_PATH +
"systemforms?$select=formid,name,formxml,type,objecttypecode&$filter=(objecttypecode%20eq%20%27pinswg_" +
whichForm +
"%27and%20type%20eq%202)&$count=true",
crmHeaders
)
.then((res) => res.data)
.catch((error) => {
console.log("thiserror", error);
})
);
return axios
.get(
WEBAPI_URL +
"systemforms?$select=formid,name,formxml,type,objecttypecode&$filter=(objecttypecode%20eq%20%27pinswg_" +
whichForm +
"%27and%20type%20eq%202)&$count=true",
crmHeaders
)
.then((res) => res.data)
.catch((error) => {
console.log("thiserror", error);
});
};
export const getMandatoryFields = (whichForm) => {
return axios
.get(
WEBAPI_URL +
API_PATH +
"EntityDefinitions(LogicalName='pinswg_" +
whichForm +
"')/Attributes?$count=true&$select=LogicalName,RequiredLevel",
@@ -118,7 +118,6 @@ export const getPickLists = (whichForm) => {
return axios
.get(
WEBAPI_URL +
API_PATH +
"EntityDefinitions(LogicalName='pinswg_" +
whichForm +
"')/Attributes/Microsoft.Dynamics.CRM.PicklistAttributeMetadata?$select=LogicalName&$expand=OptionSet,GlobalOptionSet&$count=true",
@@ -131,24 +130,16 @@ export const getPickLists = (whichForm) => {
};
export const getAppealsTypes = () => {
console.log("got to axios: appeal types");
console.log("api_root: ", BASE_URL);
return (
axios
// .get(BASE_URL + "/api/lookups/pinswg_appealcasetype", {
// httpsAgent: new https.Agent({ rejectUnauthorized: false }),
// })
.get(
WEBAPI_URL +
API_PATH +
"stringmaps?$filter=attributename%20eq%20%27pinswg_appealcasetype%27&$count=true&$select=value,stringmapid,organizationid,attributevalue",
crmHeaders
)
.then((res) => res.data)
.catch((error) => {
console.log("thiserror", error);
})
);
return axios
.get(
WEBAPI_URL +
"stringmaps?$filter=attributename%20eq%20%27pinswg_appealcasetype%27&$count=true&$select=value,stringmapid,organizationid,attributevalue",
crmHeaders
)
.then((res) => res.data)
.catch((error) => {
console.log("thiserror", error);
});
};
export const getBasicSearch2 = (searchString) => {
@@ -255,23 +246,12 @@ export const getAppealTypeDetail = (caseReference, appealcasetype) => {
export const getLPA = () => {
console.log("api_root: ", BASE_URL);
return (
axios
// .get(
// BASE_URL + "/api/lookups/pinswg_lpa",
// //.get("https://devcrm2016.llcdt.gov.wales/DVPINS/api/data/v8.2/accounts?$select=name",
// { httpsAgent: new https.Agent({ rejectUnauthorized: false }) }
// )
.get(
WEBAPI_URL + API_PATH + "accounts?$count=true&$select=name",
crmHeaders
)
.then((res) => res.data)
.catch((error) => {
console.log("thi serror", error);
})
);
return axios
.get(WEBAPI_URL + "accounts?$count=true&$select=name", crmHeaders)
.then((res) => res.data)
.catch((error) => {
console.log("thi serror", error);
});
};
export const getPersonalAccount = () => {
@@ -289,27 +269,39 @@ export const getPersonalAccount = () => {
});
};
function makeid(length) {
var result = "";
var characters =
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
var charactersLength = characters.length;
for (var i = 0; i < length; i++) {
result += characters.charAt(
Math.floor(Math.random() * charactersLength)
);
}
return result;
}
export const createCase = (lpaType, appealType) => {
console.log();
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)
.catch((error) => {
console.log("thi serror", error);
});
};
const lastPart = makeid(6);
const middlePart = Math.floor(100000 + Math.random() * 900000);
return "CAS-" + middlePart + "-" + lastPart.toUpperCase();
export const updateCase = (incidentID, appealTypeId) => {
return axios
.patch(
WEBAPI_URL + "incidents(" + incidentID + ")",
{
"pinswg_appealtype": appealTypeId,
},
crmHeadersReturn
)
.then((res) => {
console.log("patched ", res.data);
return res.data;
})
.catch((error) => {
console.log("thi serror", error);
});
};
// var req = new XMLHttpRequest();
@@ -378,7 +370,6 @@ export const createCase = (lpaType, appealType) => {
export const getMyCases = () => {
return axios
.get(BASE_URL + "/api/lookups/myCases", {
httpsAgent: new https.Agent({ rejectUnauthorized: false }),
})
@@ -390,7 +381,6 @@ export const getMyCases = () => {
export const getMyRepresentations = () => {
return axios
.get(BASE_URL + "/api/lookups/myRepresentations", {
httpsAgent: new https.Agent({ rejectUnauthorized: false }),
})
@@ -415,7 +405,6 @@ export const getWatchedCases = () => {
export const getAwaitingSubmission = () => {
return axios
.get(BASE_URL + "/api/lookups/awaitingSubmission", {
httpsAgent: new https.Agent({ rejectUnauthorized: false }),
})