Files
pedwfrontend/actions/index.js
T

1073 lines
35 KiB
JavaScript

import axios from "axios";
import https from "https";
import CryptoJS from "crypto-js";
import HmacSHA256 from "crypto-js/hmac-sha256";
import { has, indexOf } from "lodash";
let BASE_URL;
const port = parseInt(process.env.PORT, 10) || 3000;
if (process.browser) {
BASE_URL = window.apiRoot;
} else {
BASE_URL = process.env.API_ROOT || `http://localhost:${port}`;
}
const WORDKEY = process.env.NEXT_PUBLIC_HASHKEY;
const cache = {};
const API_PATH = "/api/data/v8.2/";
const accessTokenEndpoint = process.env.ACCESS_TOKEN_ENDPOINT;
const tenantId = process.env.TENANT;
//const WEBAPI_URL = "https://devcrm2016.llcdt.gov.wales/DVPINS" + API_PATH;
const WEBAPI_URL =
process.env.RELAY_ROOT ||
"https://dev-pedw-ns.servicebus.windows.net/dev-pedw-hc/";
const agent = new https.Agent({
rejectUnauthorized: false,
});
export const getToken = () => {
if (cache.tokenResponse) {
return cache.tokenResponse;
} else {
return axios
.post(
`${accessTokenEndpoint}${tenantId}/oauth2/v2.0/token`,
tokenBody,
tokenConfig
)
.then((res) => res.data)
.then((data) => {
cache.tokenResponse = data;
return data;
})
.catch((error) => {
console.log("error :", error.response);
// return error;
});
}
};
const tokenBody =
"grant_type=" +
process.env.GRANT_TYPE +
"&client_id=" +
process.env.CLIENT_ID +
"&client_secret=" +
process.env.CLIENT_SECRET +
"&scope=" +
"https://" +
process.env.RELAYURI +
"/.default";
const tokenConfig = {
headers: {
"Content-Type": "application/x-www-form-urlencoded",
"Cache-Control": "no-cache",
},
};
const azureHeaders = (access_token) => {
return {
headers: {
"OData-MaxVersion": "4.0",
"OData-Version": "4.0",
"Accept": "application/json",
"Prefer": 'odata.include-annotations="*",return=representation',
"Content-Type": "application/json",
"Authorization": "Bearer " + access_token,
},
};
};
const azureHeadersPaged = (access_token) => {
return {
headers: {
"OData-MaxVersion": "4.0",
"OData-Version": "4.0",
"Accept": "application/json",
"Prefer":
'odata.include-annotations="*",return=representation, odata.maxpagesize=10',
"Content-Type": "application/json",
"Authorization": "Bearer " + access_token,
},
};
};
const hashAPIPath = (queryPath) => {
var hashPath =
queryPath.indexOf("/api/proxy/") == -1
? queryPath
: queryPath.split("/api/proxy/")[1];
var hashlink = CryptoJS.HmacSHA256(
hashPath,
CryptoJS.enc.Hex.parse(WORDKEY)
);
hashlink = hashlink.toString(CryptoJS.enc.Hex);
return "&hash=" + hashlink;
};
export const getBasicSearch = (token, searchString) => {
//console.log("\n\n", token, searchString);
var queryUrl =
"incidents?$select=numberofchildincidents,_accountid_value,_customerid_value,_pinswg_associatedlpa_value,_ownerid_value,pinswg_appealcasetype,statuscode,ticketnumber,title, _primarycontactid_value&$expand=primarycontactid($select=fullname)&$filter=(contains(title, '" +
searchString +
"') or contains(ticketnumber, '" +
searchString +
"')) and pinswg_appealcasetype ne null and pinswg_publishtoweb eq true&$orderby=createdon desc&$count=true";
return axios
.get(
WEBAPI_URL + queryUrl + hashAPIPath(queryUrl),
azureHeadersPaged(token)
)
.then((res) => {
return res.data;
})
.catch((error) => {
return error.response;
});
};
export const getBasicSearchPaged = (searchString, pageNumber) => {
//console.log("\n\n", token, searchString);
//console.log(typeof pageNumber != "undefined");
var queryUrl =
"/api/proxy/incidents?$select=numberofchildincidents,_accountid_value,_customerid_value,_pinswg_associatedlpa_value,_ownerid_value,pinswg_appealcasetype,statuscode,ticketnumber,title, _primarycontactid_value&$expand=primarycontactid($select=fullname)&$filter=(contains(title, '" +
searchString +
"') or contains(ticketnumber, '" +
searchString +
"')) and pinswg_appealcasetype ne null and pinswg_publishtoweb eq true&$orderby=createdon desc&$count=true" +
(typeof pageNumber != "undefined"
? "&$skiptoken=" + '<cookie pagenumber="' + pageNumber + '" />'
: "");
//console.log(queryUrl);
return axios
.get(queryUrl + hashAPIPath(queryUrl))
.then((res) => {
// console.log(" ");
// console.log("/////////////////////");
// console.log("data:" + res.data.value);
// console.log("/////////////////////");
// console.log(" ");
return res.data;
})
.catch((error) => {
//console.log("thiserror", error);
return error.response;
});
};
export const getBasicDNSSearch = (token, searchString) => {
var queryUrl =
"incidents?$select=numberofchildincidents,_accountid_value,_customerid_value,_pinswg_associatedlpa_value,_ownerid_value,pinswg_appealcasetype,statuscode,ticketnumber,title, _primarycontactid_value&$expand=primarycontactid($select=fullname)&$filter=pinswg_appealcasetype eq 846040011 and pinswg_publishtoweb eq true&$orderby=createdon desc&$count=true";
return axios
.get(
WEBAPI_URL + queryUrl + hashAPIPath(queryUrl),
azureHeadersPaged(token)
)
.then((res) => res.data)
.catch((error) => {
return error.response;
});
};
export const getBasicDNSSearchPaged = (pageNumber) => {
var token = getToken();
var queryUrl =
"/api/proxy/incidents?$select=numberofchildincidents,_accountid_value,_customerid_value,_pinswg_associatedlpa_value,_ownerid_value,pinswg_appealcasetype,statuscode,ticketnumber,title, _primarycontactid_value&$expand=primarycontactid($select=fullname)&$filter=pinswg_appealcasetype eq 846040011 and pinswg_publishtoweb eq true&$orderby=createdon desc&$count=true" +
(typeof pageNumber != "undefined"
? "&$skiptoken=" + '<cookie pagenumber="' + pageNumber + '" />'
: "");
return axios
.get(queryUrl + hashAPIPath(queryUrl))
.then((res) => res.data)
.catch((error) => {
return error.response;
});
};
export const getAdvancedSearch = (token, searchString) => {
console.log(searchString.caseReference);
var queryString = "";
queryString +=
searchString.q != null
? "(contains(title, '" +
searchString.q +
"') or contains(ticketnumber,'" +
searchString.q +
"'))"
: "";
queryString +=
searchString.lpa != null
? (typeof searchString.q == "undefined" ? "" : " and ") +
"_pinswg_associatedlpa_value eq " +
searchString.lpa
: "";
queryString +=
searchString.apt != null
? (typeof searchString.q == "undefined" &&
typeof searchString.lpa == "undefined"
? ""
: " and ") +
"pinswg_appealcasetype eq " +
searchString.apt
: "";
var queryUrl =
"incidents?$select=numberofchildincidents,_accountid_value,_customerid_value,_pinswg_associatedlpa_value,_ownerid_value,pinswg_appealcasetype,statuscode,ticketnumber,title, _primarycontactid_value&$expand=primarycontactid($select=fullname)&$filter=" +
queryString +
" and pinswg_appealcasetype ne null and pinswg_publishtoweb eq true&$orderby=createdon desc&$count=true";
return axios
.get(
WEBAPI_URL + queryUrl + hashAPIPath(queryUrl),
azureHeadersPaged(token)
)
.then((res) => res.data)
.catch((error) => {
let ErrResponse = {
value: [],
errorCode: error.response.status,
errorMsg: error.response.statusText,
};
return ErrResponse;
});
};
export const getAdvancedSearchPaged = (searchString, pageNumber) => {
//console.log(searchString);
var token = getToken();
var queryString = "";
queryString +=
searchString.q != null
? "(contains(title, '" +
searchString.q +
"') or contains(ticketnumber,'" +
searchString.q +
"'))"
: "";
queryString +=
searchString.lpa != null
? (typeof searchString.q == "undefined" ? "" : " and ") +
"_pinswg_associatedlpa_value eq " +
searchString.lpa
: "";
queryString +=
searchString.apt != null
? (typeof searchString.q == "undefined" &&
typeof searchString.lpa == "undefined"
? ""
: " and ") +
"pinswg_appealcasetype eq " +
searchString.apt
: "";
var queryUrl =
"/api/proxy/incidents?$select=numberofchildincidents,_accountid_value,_customerid_value,_pinswg_associatedlpa_value,_ownerid_value,pinswg_appealcasetype,statuscode,ticketnumber,title, _primarycontactid_value&$expand=primarycontactid($select=fullname)&$filter=" +
queryString +
" and pinswg_appealcasetype ne null and pinswg_publishtoweb eq true&$orderby=createdon desc&$count=true" +
(typeof pageNumber != "undefined"
? "&$skiptoken=" + ('<cookie pagenumber="' + pageNumber + '" />')
: "");
return axios
.get(queryUrl + hashAPIPath(queryUrl))
.then((res) => res.data)
.catch((error) => {
let ErrResponse = {
value: [],
errorCode: error.response.status,
errorMsg: error.response.statusText,
};
return ErrResponse;
});
};
export const getBasicSearchDetails = (
token,
appealTypeName,
caseReference,
primaryIdAttribute,
incidentID
) => {
//console.log("check appealtype:", appealType, caseReference);
var queryUrl =
appealTypeName +
"?$filter=_" +
primaryIdAttribute +
"s_value eq " +
incidentID +
"&$count=true";
return axios
.get(
WEBAPI_URL + queryUrl + hashAPIPath(queryUrl),
azureHeadersPaged(token)
)
.then((res) => res.data)
.catch((error) => {
console.log("this error", error);
});
};
export const getBasicSearchDetailsPaged = (
appealTypeName,
caseReference,
primaryIdAttribute,
incidentID
) => {
//console.log("check appealtype:", appealType, caseReference);
var queryUrl =
"/api/proxy/" +
appealTypeName +
"?$filter=_" +
primaryIdAttribute +
"s_value eq " +
incidentID +
"&$count=true";
return axios
.get(queryUrl + hashAPIPath(queryUrl))
.then((res) => res.data)
.catch((error) => {
console.log("this error", error);
});
};
export const getSearchDocumentDetails = (token, incidentID) => {
console.log(incidentID);
var queryUrl =
"pinswg_documents?$count=true&$filter=_pinswg_documentids_value eq " +
incidentID +
" and pinswg_publishtoweb eq true&$select=pinswg_isharedocumentlocations,_pinswg_documentids_value,pinswg_isharelabelcasetype,pinswg_isharelabellpaname,pinswg_publishtoweb,pinswg_uploadstatus,pinswg_isharedocumentclassification,pinswg_isharedocumentreference";
return axios
.get(
WEBAPI_URL + queryUrl + hashAPIPath(queryUrl),
azureHeadersPaged(token)
)
.then((res) => res.data)
.catch((error) => {
console.log("thiserror", error);
});
};
export const getSearchDocumentHistory = (token, documentID) => {
var queryUrl =
"pinswg_documenthistories?$count=true&$select=_pinswg_documentid_value,pinswg_createddate,pinswg_state,pinswg_fileexists,statecode,pinswg_publisheddate&$filter=_pinswg_documentid_value eq " +
documentID;
return axios
.get(
WEBAPI_URL + queryUrl + hashAPIPath(queryUrl),
azureHeadersPaged(token)
)
.then((res) => res.data)
.catch((error) => {
console.log("thiserror", error);
});
};
export const getSearchDocumentDetailsPaged = (incidentID, pageNumber) => {
console.log(incidentID);
var token = getToken();
var queryUrl =
"/api/proxy/pinswg_documents?$count=true&$filter=_pinswg_documentids_value eq " +
incidentID +
" and pinswg_publishtoweb eq true&$select=pinswg_isharedocumentlocations,_pinswg_documentids_value,pinswg_isharelabelcasetype,pinswg_isharelabellpaname,pinswg_publishtoweb,pinswg_uploadstatus,pinswg_isharedocumentclassification,pinswg_isharedocumentreference" +
(typeof pageNumber != "undefined"
? "&$skiptoken=" +
encodeURI('<cookie pagenumber="' + pageNumber + '" />')
: "");
return axios
.get(queryUrl + hashAPIPath(queryUrl))
.then((res) => res.data)
.catch((error) => {
console.log("thiserror", error);
});
};
export const getSearchDocumentHistoryPaged = (documentID, pageNumber) => {
var token = getToken();
var queryUrl =
"/api/proxy/pinswg_documenthistories?$count=true&$select=_pinswg_documentid_value,pinswg_createddate,pinswg_state,pinswg_fileexists,statecode,pinswg_publisheddate&$filter=_pinswg_documentid_value eq " +
documentID +
(typeof pageNumber != "undefined"
? "&$skiptoken=" + ('<cookie pagenumber="' + pageNumber + '" />')
: "");
return axios
.get(queryUrl + hashAPIPath(queryUrl))
.then((res) => res.data)
.catch((error) => {
console.log("thiserror", error);
});
};
export const getSearchDocumentDetails1 = (incidentID) => {
var queryUrl =
"/api/proxy/pinswg_documents?$count=true&$filter=pinswg_publishtoweb eq true and _pinswg_documentids_value eq " +
incidentID +
"&$select=pinswg_isharedocumentlocations,_pinswg_documentids_value,pinswg_isharelabelcasetype,pinswg_isharelabellpaname,pinswg_publishtoweb,pinswg_uploadstatus,pinswg_isharedocumentclassification,pinswg_isharedocumentreference";
return axios
.get(queryUrl + hashAPIPath(queryUrl))
.then((res) => res.data)
.catch((error) => {
console.log("thiserror", error);
});
};
export const getSearchDocumentDetails1Paged = (incidentID, pageNumber) => {
var queryUrl =
"/api/proxy/pinswg_documents?$count=true&$filter=pinswg_publishtoweb eq true and _pinswg_documentids_value eq " +
incidentID +
"&$select=pinswg_isharedocumentlocations,_pinswg_documentids_value,pinswg_isharelabelcasetype,pinswg_isharelabellpaname,pinswg_publishtoweb,pinswg_uploadstatus,pinswg_isharedocumentclassification,pinswg_isharedocumentreference" +
(typeof pageNumber != "undefined"
? "&$skiptoken=" + ('<cookie pagenumber="' + pageNumber + '" />')
: "");
return axios
.get(queryUrl + hashAPIPath(queryUrl))
.then((res) => res.data)
.catch((error) => {
console.log("thiserror", error);
});
};
export const getSearchDocumentHistory1 = (documentID) => {
var queryUrl =
"/api/proxy/pinswg_documenthistories?$count=true&$select=_pinswg_documentid_value,pinswg_createddate,pinswg_state,pinswg_fileexists,statecode,pinswg_publisheddate&$filter=_pinswg_documentid_value eq " +
documentID;
return axios
.get(queryUrl + hashAPIPath(queryUrl))
.then((res) => {
return res.data;
})
.catch((error) => {
console.log("thiserror", error);
});
};
export const getSearchDocumentHistory1Paged = (documentID, pageNumber) => {
var queryUrl =
"/api/proxy/pinswg_documenthistories?$count=true&$select=_pinswg_documentid_value,pinswg_createddate,pinswg_state,pinswg_fileexists,statecode,pinswg_publisheddate&$filter=_pinswg_documentid_value eq " +
documentID +
(typeof pageNumber != "undefined"
? "&$skiptoken=" + ('<cookie pagenumber="' + pageNumber + '" />')
: "");
return axios
.get(queryUrl + hashAPIPath(queryUrl))
.then((res) => {
return res.data;
})
.catch((error) => {
console.log("thiserror", error);
});
};
export const getBasicDNSSearchDetails = (token, appealType, caseReference) => {
var queryUrl =
"pinswg_dnses?$filter=pinswg_name eq '" +
caseReference +
"'&$count=true";
return axios
.get(
WEBAPI_URL + queryUrl + hashAPIPath(queryUrl),
azureHeadersPaged(token)
)
.then((res) => res.data)
.catch((error) => {
console.log("thiserror", error);
});
};
export const getBasicDNSSearchDetailsPaged = (caseReference) => {
var token = getToken();
var queryUrl =
"/api/proxy/pinswg_dnses?$filter=pinswg_name eq '" +
caseReference +
"'&$count=true";
return axios
.get(queryUrl + hashAPIPath(queryUrl))
.then((res) => res.data)
.catch((error) => {
console.log("thiserror", error);
});
};
export const getLinkedCases = (parentIncidentid) => {
//console.log(parentIncidentid);
var queryUrl =
"/api/proxy/incidents?$count=true&$filter=_parentcaseid_value eq " +
parentIncidentid +
" and pinswg_appealcasetype ne null and pinswg_publishtoweb eq true &$select=title, incidentid";
return axios
.get(queryUrl + hashAPIPath(queryUrl))
.then((res) => {
//console.log(" linked date", res.data);
return res.data;
})
.catch((error) => {
console.log("thiserror", error);
});
};
export const getFormData = (token, whichForm) => {
var queryUrl =
"systemforms?$select=formid,name,formxml,type,objecttypecode&$filter=(objecttypecode%20eq%20%27pinswg_" +
whichForm +
"%27and%20type%20eq%202)&$count=true&$top=201";
return axios
.get(WEBAPI_URL + queryUrl + hashAPIPath(queryUrl), azureHeaders(token))
.then((res) => res.data)
.catch((error) => {
console.log("thiserror", error);
});
};
export const getMandatoryFields = (token, whichForm) => {
var queryUrl =
"EntityDefinitions(LogicalName='pinswg_" +
whichForm +
"')/Attributes?$count=true&$select=LogicalName,RequiredLevel";
return axios
.get(WEBAPI_URL + queryUrl + hashAPIPath(queryUrl), azureHeaders(token))
.then((res) => res.data)
.catch((error) => {
console.log("thiserror", error);
});
};
export const getPickLists = (token, whichForm) => {
var queryUrl =
"EntityDefinitions(LogicalName='pinswg_" +
whichForm +
"')/Attributes/Microsoft.Dynamics.CRM.PicklistAttributeMetadata?$select=LogicalName&$expand=OptionSet,GlobalOptionSet&$count=true";
return axios
.get(WEBAPI_URL + queryUrl + hashAPIPath(queryUrl), azureHeaders(token))
.then((res) => res.data)
.catch((error) => {
console.log("thiserror", error);
});
};
export const getAppealsTypes = (token) => {
var queryUrl =
"stringmaps?$filter=objecttypecode eq 'incident' and attributename eq 'pinswg_appealcasetype' and value ne 'LDP' and value ne 'Misc Casework'&$count=true&$select=value,stringmapid,organizationid,attributevalue&$orderby=value asc";
return axios
.get(WEBAPI_URL + queryUrl + hashAPIPath(queryUrl), azureHeaders(token))
.then((res) => res.data)
.catch((error) => {
console.log(error);
let ErrResponse = {
value: [],
errorCode: error.response.status,
errorMsg: error.response.statusText,
};
return ErrResponse;
});
};
export const getLPA = (token) => {
// console.log("api_root: ", BASE_URL);
var queryUrl =
"accounts?$count=true&$filter=pinswg_isalocalplanningauthorityaccount eq 846040000&$select=name&$orderby=name asc";
return axios
.get(WEBAPI_URL + queryUrl + hashAPIPath(queryUrl), azureHeaders(token))
.then((res) => {
//console.log(res.data);
return res.data;
})
.catch((error) => {
let ErrResponse = {
value: [],
errorCode: error.response.status,
errorMsg: error.response.statusText,
};
return ErrResponse;
});
};
export const getPersonalAccount = (token, contactid) => {
var queryUrl =
"contacts(" +
contactid +
")?$select=firstname, lastname, emailaddress1, telephone1, company, address1_line1,address1_line2,address1_city, address1_county,address1_postalcode&$count=true";
return axios
.get(WEBAPI_URL + queryUrl + hashAPIPath(queryUrl), azureHeaders(token))
.then((res) => {
console.log(res.data);
return res.data;
})
.catch((error) => {
let ErrResponse = {
value: [],
errorCode: error.response.status,
errorMsg: error.response.statusText,
};
return ErrResponse;
});
};
export const getAppealID = (
caseReference,
updateFormCollection,
primaryAttribute
) => {
const queryUrl =
"/api/proxy/" +
updateFormCollection +
"?$count=true&$select=_" +
primaryAttribute +
"s_value&$filter=pinswg_name eq '" +
caseReference +
"'";
console.log("proxy url ", queryUrl);
return axios
.get(
WEBAPI_URL + queryUrl + hashAPIPath(queryUrl),
azureHeaders(getToken())
)
.then((res) => {
var appealID = res.data.value[0][primaryAttribute];
return appealID;
})
.catch((error) => {
console.log("thi serror", error);
});
};
export const getLogin = (emailAddress, pwd) => {
var queryUrl =
"/api/proxy/contacts?$filter=emailaddress1 eq '" +
emailAddress +
"' and pinswg_custom_password eq '" +
pwd +
"'&$count=true&$select=emailaddress1,%20contactid,pinswg_custom_password, yomifullname, firstname, lastname";
return axios
.get(queryUrl + hashAPIPath(queryUrl))
.then((res) => res.data)
.catch((error) => {
console.log("thiserror", error);
});
};
export const createCase = (token, appealTypeId, lpaID, contactid) => {
appealTypeId = parseInt(appealTypeId);
var queryUrl = "incidents";
var data = JSON.stringify({
"title": "insertion test case",
"caseorigincode": 3,
"customerid_contact@odata.bind": "/contacts(" + contactid + ")",
"pinswg_appealcasetype": appealTypeId,
"pinswg_AssociatedLPA@odata.bind": "/accounts(" + lpaID + ")",
});
var config = {
method: "post",
url: queryUrl + hashAPIPath(queryUrl),
headers: {
"OData-MaxVersion": "4.0",
"OData-Version": "4.0",
"Accept": "application/json",
"Prefer": 'odata.include-annotations="*",return=representation',
"Content-Type": "application/json",
"ServiceBusAuthorization": token,
},
data: data,
};
// console.log(config);
return axios(config)
.then((res) => {
// console.log("posted ", res.data);
return res.data;
})
.catch((error) => {
console.log("this serror", error);
});
};
export const updateCase = async (
incidentId,
updateBody,
updateFormCollection,
primaryAttribute,
caseReference
) => {
var data = JSON.stringify(updateBody);
var appealObj = await getAppealID(
caseReference,
updateFormCollection,
primaryAttribute
);
console.log("appeal obj ", appealObj);
var queryUrl = "/api/proxy/" + updateFormCollection + "(" + appealObj + ")";
var config = {
method: "patch",
//url: updateFormCollection + "(" + incidentId + ")",
url: queryUrl + hashAPIPath(queryUrl),
headers: {
"OData-MaxVersion": "4.0",
"OData-Version": "4.0",
"Accept": "application/json",
"Prefer": 'odata.include-annotations="*",return=representation',
"Content-Type": "application/json",
"Authorization": getToken(),
},
data: data,
};
//console.log(config);
return axios(config)
.then((res) => {
//console.log("patched ", res.data);
return res.data;
})
.catch((error) => {
console.log("thi serror", error);
});
};
export const getMyCases = (token, loggedInUserId) => {
//console.log("in action ", loggedInUserId);
var queryUrl =
"incidents?$select=ticketnumber,casetypecode,createdon,_customerid_value,description,incidentid,pinswg_appealcasetype,_pinswg_assignedinspectrids_value,statecode,statuscode,title&$filter=_customerid_value eq " +
loggedInUserId +
" and pinswg_appealcasetype ne null&$orderby=createdon desc&$count=true&$top=3";
return axios
.get(WEBAPI_URL + queryUrl + hashAPIPath(queryUrl), azureHeaders(token))
.then((res) => {
return res.data;
})
.catch((error) => {
console.log("thi serror", error);
});
};
export const getMyRepresentations = (token, loggedInUserId) => {
var queryUrl =
"pinswg_representationses?$filter= _pinswg_contact_value eq " +
loggedInUserId +
"&$count=true&$orderby=createdon desc";
return axios
.get(WEBAPI_URL + queryUrl + hashAPIPath(queryUrl), azureHeaders(token))
.then((res) => res.data)
.catch((error) => {
console.log("this serror", error);
});
};
export const getMyRepresentationsProxy = (token, loggedInUserId) => {
var queryUrl =
"/api/proxy/pinswg_representationses?$filter= _pinswg_contact_value eq " +
loggedInUserId +
"&$count=true&$orderby=createdon desc";
return axios
.get(queryUrl + hashAPIPath(queryUrl))
.then((res) => res.data)
.catch((error) => {
console.log("this serror", error);
});
};
export const deleteMyRepresentations = (myRepresentationsID) => {
var queryUrl =
"/api/proxy/pinswg_representationses(" + myRepresentationsID + ")";
var config = {
method: "delete",
url: queryUrl + hashAPIPath(queryUrl),
headers: {
"OData-MaxVersion": "4.0",
"OData-Version": "4.0",
"Accept": "application/json",
"Prefer": 'odata.include-annotations="*",return=representation',
"Content-Type": "application/json",
"Authorization": getToken(),
},
};
// console.log(config);
return axios(config)
.then((res) => {
//console.log("deleted ", res.data);
return res.data;
})
.catch((error) => {
console.log("this serror", error);
});
};
export const getRepresentations = (incidentID) => {
var queryUrl =
"/api/proxy/pinswg_representationses?$filter= _pinswg_case_value eq " +
incidentID +
" and pinswg_publishtoweb eq true&$count=true&$orderby=createdon desc";
return axios
.get(queryUrl + hashAPIPath(queryUrl))
.then((res) => res.data)
.catch((error) => {
console.log("this serror", error);
});
};
export const getRepresentationsProxy = (token, incidentID) => {
var queryUrl =
"/api/proxy/pinswg_representationses?$filter= _pinswg_case_value eq " +
incidentID +
"&$count=true&$orderby=createdon desc";
return axios
.get(queryUrl + hashAPIPath(queryUrl))
.then((res) => res.data)
.catch((error) => {
console.log("this serror", error);
});
};
export const getWatchedCases = (token, loggedInUserId) => {
var queryUrl =
"pinswg_watchlists?$filter= _pinswg_contact_value eq " +
loggedInUserId +
"&$count=true&$orderby=createdon desc";
return axios
.get(WEBAPI_URL + queryUrl + hashAPIPath(queryUrl), azureHeaders(token))
.then((res) => res.data)
.catch((error) => {
console.log("this serror", error);
});
};
export const getWatchedCasesProxy = (token, loggedInUserId) => {
var queryUrl =
"/api/proxy/pinswg_watchlists?$filter= _pinswg_contact_value eq " +
loggedInUserId +
"&$count=true&$orderby=createdon desc";
return axios
.get(queryUrl + hashAPIPath(queryUrl))
.then((res) => res.data)
.catch((error) => {
console.log("this serror", error);
});
};
export const createWatchedCases = (formValues) => {
var data = JSON.stringify(formValues);
var queryUrl = "/api/proxy/pinswg_watchlists";
var config = {
method: "post",
url: queryUrl + hashAPIPath(queryUrl),
headers: {
"OData-MaxVersion": "4.0",
"OData-Version": "4.0",
"Accept": "application/json",
"Prefer": 'odata.include-annotations="*",return=representation',
"Content-Type": "application/json",
"Authorization": getToken(),
},
data: data,
};
// console.log(config);
return axios(config)
.then((res) => {
//console.log("posted ", res.data);
return res.data;
})
.catch((error) => {
console.log("this serror", error);
});
};
export const deleteWatchedCases = (watchedCaseID) => {
var queryUrl = "/api/proxy/pinswg_watchlists(" + watchedCaseID + ")";
var config = {
method: "delete",
url: queryUrl + hashAPIPath(queryUrl),
headers: {
"OData-MaxVersion": "4.0",
"OData-Version": "4.0",
"Accept": "application/json",
"Prefer": 'odata.include-annotations="*",return=representation',
"Content-Type": "application/json",
"Authorization": getToken(),
},
};
// console.log(config);
return axios(config)
.then((res) => {
//console.log("deleted ", res.data);
return res.data;
})
.catch((error) => {
console.log("this serror", error);
});
};
export const getAwaitingSubmission = (token) => {
return axios
.get(BASE_URL + "/api/lookups/awaitingSubmission", {
httpsAgent: new https.Agent({ rejectUnauthorized: false }),
})
.then((res) => res.data)
.catch((error) => {
console.log("thi serror", error);
});
};
export const getPortalModuleDetails = (token, appealType, caseReference) => {
var queryUrl =
appealType +
"?$filter=pinswg_name eq '" +
caseReference +
"'&$count=true";
return axios
.get(WEBAPI_URL + queryUrl + hashAPIPath(queryUrl), azureHeaders(token))
.then((res) => res.data)
.catch((error) => {
console.log("thiserror", error);
});
};
export const getPortalModuleDetailsProxy = (
token,
appealType,
caseReference
) => {
var queryUrl =
"/api/proxy/" +
appealType +
"?$filter=pinswg_name eq '" +
caseReference +
"'&$count=true";
return axios
.get(queryUrl + hashAPIPath(queryUrl))
.then((res) => res.data)
.catch((error) => {
console.log("thiserror", error);
});
};
export const getEmailAccountCheck = (emailAddress) => {
var queryUrl =
"/api/proxy/contacts?$filter=emailaddress1 eq '" +
emailAddress +
"'&$count=true&$select=emailaddress1, contactid";
return axios
.get(queryUrl + hashAPIPath(queryUrl))
.then((res) => res.data)
.catch((error) => {
console.log("thiserror", error);
});
};
export const createAccount = (formValues) => {
var data = JSON.stringify(formValues);
var queryUrl = "/api/proxy/contacts";
var config = {
method: "post",
url: queryUrl + hashAPIPath(queryUrl),
headers: {
"OData-MaxVersion": "4.0",
"OData-Version": "4.0",
"Accept": "application/json",
"Prefer": 'odata.include-annotations="*",return=representation',
"Content-Type": "application/json",
"Authorization": getToken(),
},
data: data,
};
// console.log(config);
return axios(config)
.then((res) => {
// console.log("posted ", res.data);
return res.data;
})
.catch((error) => {
console.log("this serror", error);
});
};
export const updateAccount = (contactId, updateBody) => {
var data = JSON.stringify(updateBody);
var queryUrl = "/api/proxy/contacts(" + contactId + ")";
var config = {
method: "patch",
url: queryUrl + hashAPIPath(queryUrl),
headers: {
"OData-MaxVersion": "4.0",
"OData-Version": "4.0",
"Accept": "application/json",
"Prefer": 'odata.include-annotations="*",return=representation',
"Content-Type": "application/json",
"Authorization": getToken(),
},
data: data,
};
// console.log(config);
return axios(config)
.then((res) => {
//console.log("posted ", res.data);
return res.data;
})
.catch((error) => {
console.log("this serror", error);
});
};
export const updatePassword = (contactId, newpassword) => {
let updateBody = { "pinswg_custom_password": newpassword };
var data = JSON.stringify(updateBody);
var queryUrl = "/api/proxy/contacts(" + contactId + ")";
var config = {
method: "patch",
url: queryUrl + hashAPIPath(queryUrl),
headers: {
"OData-MaxVersion": "4.0",
"OData-Version": "4.0",
"Accept": "application/json",
"Prefer": 'odata.include-annotations="*",return=representation',
"Content-Type": "application/json",
"Authorization": getToken(),
},
data: data,
};
// console.log(config);
return axios(config)
.then((res) => {
//console.log("posted ", res.data);
return res.data;
})
.catch((error) => {
console.log("this serror", error);
});
};