diff --git a/actions/index.js b/actions/index.js index a41fb24e..809ce6c5 100644 --- a/actions/index.js +++ b/actions/index.js @@ -121,16 +121,14 @@ export const getBasicSearch = (token, searchString) => { return axios .get( BASE_URL + - "/api/endpoint/getbasicsearch_api?token=" + - token + - "&searchString=" + - searchString, - azureHeadersPaged(token) + "api/endpoint/getbasicsearch_api?searchString=" + + searchString ) .then((res) => { return res.data; }) .catch((error) => { + console.log(error); return error.response; }); }; @@ -157,10 +155,7 @@ export const getBasicDNSSearch = (token, searchString) => { "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( - BASE_URL + "/api/endpoint/getbasicdnssearch_api?token=" + token, - azureHeadersPaged(token) - ) + .get(BASE_URL + "/api/endpoint/getbasicdnssearch_api") .then((res) => res.data) .catch((error) => { return error.response; @@ -182,11 +177,8 @@ export const getAdvancedSearch = (token, searchString) => { return axios .get( BASE_URL + - "/api/endpoint/getadvancedsearch_api?token=" + - token + - "&searchstring=" + - JSON.stringify(searchString), - azureHeadersPaged(token) + "/api/endpoint/getadvancedsearch_api?searchstring=" + + JSON.stringify(searchString) ) .then((res) => res.data) .catch((error) => { @@ -227,19 +219,15 @@ export const getBasicSearchDetails = ( primaryIdAttribute, incidentID ) => { - //console.log("check appealtype:", appealTypeName, caseReference); - - var queryUrl = - appealTypeName + - "?$filter=_" + - primaryIdAttribute + - "s_value eq " + - incidentID + - "&$count=true"; return axios .get( - WEBAPI_URL + queryUrl + hashAPIPath(queryUrl), - azureHeadersPaged(token) + BASE_URL + + "/api/endpoint/getbasicsearchdetails_api?appealTypeName=" + + appealTypeName + + "&primaryIdAttribute=" + + primaryIdAttribute + + "&incidentID=" + + incidentID ) .then((res) => res.data) .catch((error) => { @@ -297,20 +285,17 @@ export const getSearchDocumentDetailsPaged = (incidentID, pageNumber) => { }; export const getSearchDocumentHistory = (documentID) => { - return ( - axios - //.get(queryUrl + hashAPIPath(queryUrl)) - .get( - "/api/endpoint/getsearchdocumenthistory_api?documentid=" + - documentID - ) - .then((res) => { - return res.data; - }) - .catch((error) => { - console.log("thiserror", error); - }) - ); + return axios + .get( + "/api/endpoint/getsearchdocumenthistory_api?documentid=" + + documentID + ) + .then((res) => { + return res.data; + }) + .catch((error) => { + console.log("thiserror", error); + }); }; export const getSearchDocumentHistoryPaged = (documentID, pageNumber) => { @@ -350,10 +335,7 @@ export const getLinkedCases = (parentIncidentid) => { export const getAppealsTypes = (token) => { return axios - .get( - BASE_URL + "/api/endpoint/getappealtypes_api?token=" + token, - azureHeaders(token) - ) + .get(BASE_URL + "/api/endpoint/getappealtypes_api") .then((res) => res.data) .catch((error) => { console.log(error); @@ -369,10 +351,7 @@ export const getAppealsTypes = (token) => { export const getLPA = (token) => { return axios - .get( - BASE_URL + "/api/endpoint/getlpa_api?token=" + token, - azureHeaders(token) - ) + .get(BASE_URL + "/api/endpoint/getlpa_api") .then((res) => { //console.log(res.data); return res.data; @@ -391,12 +370,8 @@ export const getLPA = (token) => { // iteration 2 methods export const getFormData = (token, whichForm) => { - var queryUrl = - "systemforms?$select=formid,name,formxml,type,objecttypecode&$filter=(objecttypecode eq 'pinswg_" + - whichForm + - "' and type eq 2)&$count=true&$top=201"; return axios - .get(WEBAPI_URL + queryUrl + hashAPIPath(queryUrl), azureHeaders(token)) + .get("/api/endpoint/getformdata_api?whichForm=" + whichForm) .then((res) => res.data) .catch((error) => { console.log("thiserror", error); @@ -404,12 +379,8 @@ export const getFormData = (token, whichForm) => { }; 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)) + .get("/api/endpoint/getmandatoryfields_api?whichForm=" + whichForm) .then((res) => res.data) .catch((error) => { console.log("thiserror", error); @@ -417,12 +388,8 @@ export const getMandatoryFields = (token, whichForm) => { }; 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)) + .get("/api/endpoint/getpicklists_api?whichForm=" + whichForm) .then((res) => res.data) .catch((error) => { console.log("thiserror", error); @@ -430,13 +397,8 @@ export const getPickLists = (token, whichForm) => { }; 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)) + .get("/api/endpoint/getpersonalaccount_api?contactid=" + contactid) .then((res) => { console.log(res.data); return res.data; @@ -529,9 +491,7 @@ export const getMyCases = (token, loggedInUserId) => { return axios .get( BASE_URL + - "/api/endpoint/getmycases_api?token=" + - token + - "&loggedInUserId=" + + "/api/endpoint/getmycases_api?loggedInUserId=" + loggedInUserId ) .then((res) => { @@ -546,9 +506,7 @@ export const getMyRepresentations = (token, loggedInUserId) => { return axios .get( BASE_URL + - "/api/endpoint/getmyrepresentations_api?token=" + - token + - "&loggedInUserId=" + + "/api/endpoint/getmyrepresentations_api?loggedInUserId=" + loggedInUserId ) .then((res) => res.data) @@ -561,9 +519,7 @@ export const getMyRepresentationsProxy = (token, loggedInUserId) => { return axios .get( BASE_URL + - "/api/endpoint/getmyrepresentationsproxy_api?token=" + - token + - "&loggedInUserId=" + + "/api/endpoint/getmyrepresentationsproxy_api?loggedInUserId=" + loggedInUserId ) .then((res) => res.data) @@ -586,9 +542,7 @@ export const getRepresentationsProxy = (token, incidentID) => { .get(queryUrl + hashAPIPath(queryUrl)) .get( BASE_URL + - "/api/endpoint/getrepresentationsproxy_api?token=" + - token + - "&incidentID=" + + "/api/endpoint/getrepresentationsproxy_api?incidentID=" + incidentID ) .then((res) => res.data) @@ -601,9 +555,7 @@ export const getWatchedCases = (token, loggedInUserId) => { return axios .get( BASE_URL + - "/api/endpoint/getwatchedcases_api?token=" + - token + - "&loggedInUserId=" + + "/api/endpoint/getwatchedcases_api?loggedInUserId=" + loggedInUserId ) .then((res) => res.data) @@ -616,9 +568,7 @@ export const getWatchedCasesProxy = (token, loggedInUserId) => { return axios .get( BASE_URL + - "/api/endpoint/getwatchedcasesproxy_api?token=" + - token + - "&loggedInUserId=" + + "/api/endpoint/getwatchedcasesproxy_api?loggedInUserId=" + loggedInUserId ) .then((res) => res.data) @@ -642,9 +592,7 @@ export const getPortalModuleDetails = (token, appealType, caseReference) => { return axios .get( BASE_URL + - "/api/endpoint/getportalmoduledetails_api?token=" + - token + - "&appealType=" + + "/api/endpoint/getportalmoduledetails_api?appealType=" + appealType + "&caseReference=" + caseReference diff --git a/components/search/dnssearchresults.js b/components/search/dnssearchresults.js index 9551cadf..777a59f7 100644 --- a/components/search/dnssearchresults.js +++ b/components/search/dnssearchresults.js @@ -260,7 +260,6 @@ const DNSSearchResults = (props) => { getBasicDNSSearchPaged(pageNumber) .then((data) => { - console.log(data); setSearchResults(data); return data; }) diff --git a/components/utils/index.js b/components/utils/index.js index a77cde8a..8c8af516 100644 --- a/components/utils/index.js +++ b/components/utils/index.js @@ -90,3 +90,21 @@ export const getSearchDetailsPaged = (searchResultsObj) => { // console.log(detailsArr); return Promise.all(detailsArr); }; + +// export const absoluteUrl = (req, setLocalhost) => { +// var protocol = "https:"; +// var host = req +// ? req.headers["x-forwarded-host"] || req.headers["host"] +// : window.location.host; + +// if (host.indexOf("localhost") > -1) { +// if (setLocalhost) host = setLocalhost; +// protocol = "http:"; +// } + +// return { +// protocol: protocol, +// host: host, +// origin: protocol + "//" + host, +// }; +// }; diff --git a/pages/api/endpoint/getadvancedsearch_api.js b/pages/api/endpoint/getadvancedsearch_api.js index d25feeee..bc0f31ba 100644 --- a/pages/api/endpoint/getadvancedsearch_api.js +++ b/pages/api/endpoint/getadvancedsearch_api.js @@ -22,7 +22,7 @@ const hashAPIPath = (queryPath) => { export default async function ApiProxy(req, res) { var searchString = req.query.searchstring; - var token = req.query.token; + var token = await getToken(); searchString = JSON.parse(searchString); @@ -61,7 +61,7 @@ export default async function ApiProxy(req, res) { return axios .get( WEBAPI_URL + queryUrl + hashAPIPath(queryUrl), - azureHeadersPaged(token) + azureHeadersPaged(token.access_token) ) .then(({ data }) => { res.status(200).json(data); diff --git a/pages/api/endpoint/getadvancedsearchpaged_api.js b/pages/api/endpoint/getadvancedsearchpaged_api.js index 9f54e0ec..8d6d7c73 100644 --- a/pages/api/endpoint/getadvancedsearchpaged_api.js +++ b/pages/api/endpoint/getadvancedsearchpaged_api.js @@ -1,6 +1,7 @@ import axios from "axios"; import https from "https"; import CryptoJS from "crypto-js"; +import _ from "lodash"; import { getToken, azureHeadersPaged } from "../../../actions"; const WORDKEY = process.env.HASHKEY; @@ -18,7 +19,7 @@ const hashAPIPath = (queryPath) => { //return "&hash=" + hashlink; - return (hashPath.indexOf("?") > -1 ? "&hash=" : "?hash=") + hashlink; + return (queryPath.indexOf("?") > -1 ? "&hash=" : "?hash=") + hashlink; }; export default async function ApiProxy(req, res) { @@ -69,6 +70,10 @@ export default async function ApiProxy(req, res) { azureHeadersPaged(token.access_token) ) .then(({ data }) => { + var dataStr; + _.has(data, "@odata.nextLink") == true && + ((dataStr = JSON.stringify(data["@odata.nextLink"])), + (data["@odata.nextLink"] = dataStr.split("/v8.2/")[1])); res.status(200).json(data); }) .catch(({ err }) => { diff --git a/pages/api/endpoint/getappealid_api.js b/pages/api/endpoint/getappealid_api.js index 46c9aace..8892e99f 100644 --- a/pages/api/endpoint/getappealid_api.js +++ b/pages/api/endpoint/getappealid_api.js @@ -1,7 +1,7 @@ import axios from "axios"; import https from "https"; import CryptoJS from "crypto-js"; -import { getToken, azureHeadersPaged } from "../../../actions"; +import { getToken, azureHeaders } from "../../../actions"; const WORDKEY = process.env.HASHKEY; const WEBAPI_URL = @@ -34,7 +34,7 @@ export default async function ApiProxy(req, res) { return axios .get( WEBAPI_URL + queryUrl + hashAPIPath(queryUrl), - azureHeadersPaged(token.access_token) + azureHeaders(token.access_token) ) .then(({ data }) => { res.status(200).json(data); diff --git a/pages/api/endpoint/getappealtypes_api.js b/pages/api/endpoint/getappealtypes_api.js index 0fc9f186..19f56d8b 100644 --- a/pages/api/endpoint/getappealtypes_api.js +++ b/pages/api/endpoint/getappealtypes_api.js @@ -21,13 +21,16 @@ const hashAPIPath = (queryPath) => { }; export default async function ApiProxy(req, res) { - var token = req.query.token; + var token = await getToken(); 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)) + .get( + WEBAPI_URL + queryUrl + hashAPIPath(queryUrl), + azureHeaders(token.access_token) + ) .then(({ data }) => { res.status(200).json(data); }) diff --git a/pages/api/endpoint/getbasicdnssearch_api.js b/pages/api/endpoint/getbasicdnssearch_api.js index 1f45571f..fa94439d 100644 --- a/pages/api/endpoint/getbasicdnssearch_api.js +++ b/pages/api/endpoint/getbasicdnssearch_api.js @@ -1,7 +1,7 @@ import axios from "axios"; import https from "https"; import CryptoJS from "crypto-js"; -import { getToken, azureHeadersPaged } from "../../../actions"; +import { getToken, azureHeaders, azureHeadersPaged } from "../../../actions"; const WORDKEY = process.env.HASHKEY; @@ -22,17 +22,15 @@ const hashAPIPath = (queryPath) => { }; export default async function ApiProxy(req, res) { - var token = req.query.token; + var token = await getToken(); 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"; - console.log(WEBAPI_URL + queryUrl + hashAPIPath(queryUrl)); - return axios .get( WEBAPI_URL + queryUrl + hashAPIPath(queryUrl), - azureHeadersPaged(token) + azureHeadersPaged(token.access_token) ) .then(({ data }) => { res.status(200).json(data); diff --git a/pages/api/endpoint/getbasicdnssearchdetails_api.js b/pages/api/endpoint/getbasicdnssearchdetails_api.js index acee0cb8..c012d345 100644 --- a/pages/api/endpoint/getbasicdnssearchdetails_api.js +++ b/pages/api/endpoint/getbasicdnssearchdetails_api.js @@ -22,7 +22,7 @@ const hashAPIPath = (queryPath) => { export default async function ApiProxy(req, res) { var caseReference = req.query.caseReference; - var token = req.query.token; + var token = await getToken(); var queryUrl = "pinswg_dnses?$filter=pinswg_name eq '" + @@ -32,7 +32,7 @@ export default async function ApiProxy(req, res) { return axios .get( WEBAPI_URL + queryUrl + hashAPIPath(queryUrl), - azureHeadersPaged(token) + azureHeaders(token.access_token) ) .then(({ data }) => { res.status(200).json(data); diff --git a/pages/api/endpoint/getbasicdnssearchdetailspaged_api.js b/pages/api/endpoint/getbasicdnssearchdetailspaged_api.js index 22782f99..2ce51215 100644 --- a/pages/api/endpoint/getbasicdnssearchdetailspaged_api.js +++ b/pages/api/endpoint/getbasicdnssearchdetailspaged_api.js @@ -1,6 +1,7 @@ import axios from "axios"; import https from "https"; import CryptoJS from "crypto-js"; +import _ from "lodash"; import { getToken, azureHeadersPaged } from "../../../actions"; const WORDKEY = process.env.HASHKEY; @@ -36,7 +37,11 @@ export default async function ApiProxy(req, res) { azureHeadersPaged(token.access_token) ) .then(({ data }) => { - res.status(200).json(data); + var dataStr; + _.has(data, "@odata.nextLink") == true && + ((dataStr = JSON.stringify(data["@odata.nextLink"])), + (data["@odata.nextLink"] = dataStr.split("/v8.2/")[1])); + return res.status(200).json(data); }) .catch(({ err }) => { res.status(400).json(err); diff --git a/pages/api/endpoint/getbasicdnssearchpaged_api.js b/pages/api/endpoint/getbasicdnssearchpaged_api.js index 18b4eb04..76fb3db5 100644 --- a/pages/api/endpoint/getbasicdnssearchpaged_api.js +++ b/pages/api/endpoint/getbasicdnssearchpaged_api.js @@ -1,6 +1,7 @@ import axios from "axios"; import https from "https"; import CryptoJS from "crypto-js"; +import _ from "lodash"; import { getToken, azureHeadersPaged } from "../../../actions"; const WORDKEY = process.env.HASHKEY; @@ -31,15 +32,17 @@ export default async function ApiProxy(req, res) { ? "&$skiptoken=" + '' : ""); - console.log(WEBAPI_URL + queryUrl + hashAPIPath(queryUrl)); - return axios .get( WEBAPI_URL + queryUrl + hashAPIPath(queryUrl), azureHeadersPaged(token.access_token) ) .then(({ data }) => { - res.status(200).json(data); + var dataStr; + _.has(data, "@odata.nextLink") == true && + ((dataStr = JSON.stringify(data["@odata.nextLink"])), + (data["@odata.nextLink"] = dataStr.split("/v8.2/")[1])); + return res.status(200).json(data); }) .catch(({ err }) => { res.status(400).json(err); diff --git a/pages/api/endpoint/getbasicsearch_api.js b/pages/api/endpoint/getbasicsearch_api.js index 4a0e8185..b9b87347 100644 --- a/pages/api/endpoint/getbasicsearch_api.js +++ b/pages/api/endpoint/getbasicsearch_api.js @@ -22,7 +22,7 @@ const hashAPIPath = (queryPath) => { export default async function ApiProxy(req, res) { var searchString = req.query.searchString; - var token = req.query.token; + var token = await getToken(); 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, '" + @@ -34,7 +34,7 @@ export default async function ApiProxy(req, res) { return axios .get( WEBAPI_URL + queryUrl + hashAPIPath(queryUrl), - azureHeadersPaged(token) + azureHeadersPaged(token.access_token) ) .then(({ data }) => { res.status(200).json(data); diff --git a/pages/api/endpoint/getbasicsearchdetails_api.js b/pages/api/endpoint/getbasicsearchdetails_api.js index dd842872..4369d0dd 100644 --- a/pages/api/endpoint/getbasicsearchdetails_api.js +++ b/pages/api/endpoint/getbasicsearchdetails_api.js @@ -1,7 +1,7 @@ import axios from "axios"; import https from "https"; import CryptoJS from "crypto-js"; -import { getToken, azureHeadersPaged } from "../../../actions"; +import { getToken, azureHeaders } from "../../../actions"; const WORDKEY = process.env.HASHKEY; const WEBAPI_URL = @@ -24,7 +24,7 @@ export default async function ApiProxy(req, res) { var appealTypeName = req.query.appealTypeName; var primaryIdAttribute = req.query.primaryIdAttribute; var incidentID = req.query.incidentID; - var token = req.query.token; + var token = await getToken(); var queryUrl = appealTypeName + @@ -37,7 +37,7 @@ export default async function ApiProxy(req, res) { return axios .get( WEBAPI_URL + queryUrl + hashAPIPath(queryUrl), - azureHeadersPaged(token) + azureHeaders(token.access_token) ) .then(({ data }) => { res.status(200).json(data); diff --git a/pages/api/endpoint/getbasicsearchdetailspaged_api.js b/pages/api/endpoint/getbasicsearchdetailspaged_api.js index 52013c62..f7100b45 100644 --- a/pages/api/endpoint/getbasicsearchdetailspaged_api.js +++ b/pages/api/endpoint/getbasicsearchdetailspaged_api.js @@ -1,6 +1,7 @@ import axios from "axios"; import https from "https"; import CryptoJS from "crypto-js"; +import _ from "lodash"; import { getToken, azureHeadersPaged } from "../../../actions"; const WORDKEY = process.env.HASHKEY; @@ -41,7 +42,11 @@ export default async function ApiProxy(req, res) { azureHeadersPaged(token.access_token) ) .then(({ data }) => { - res.status(200).json(data); + var dataStr; + _.has(data, "@odata.nextLink") == true && + ((dataStr = JSON.stringify(data["@odata.nextLink"])), + (data["@odata.nextLink"] = dataStr.split("/v8.2/")[1])); + return res.status(200).json(data); }) .catch(({ err }) => { res.status(400).json(err); diff --git a/pages/api/endpoint/getbasicsearchpaged_api.js b/pages/api/endpoint/getbasicsearchpaged_api.js index fa4f1065..81b34af5 100644 --- a/pages/api/endpoint/getbasicsearchpaged_api.js +++ b/pages/api/endpoint/getbasicsearchpaged_api.js @@ -1,6 +1,7 @@ import axios from "axios"; import https from "https"; import CryptoJS from "crypto-js"; +import _ from "lodash"; import { getToken, azureHeadersPaged } from "../../../actions"; const WORDKEY = process.env.HASHKEY; @@ -40,7 +41,11 @@ export default async function ApiProxy(req, res) { azureHeadersPaged(token.access_token) ) .then(({ data }) => { - res.status(200).json(data); + var dataStr; + _.has(data, "@odata.nextLink") == true && + ((dataStr = JSON.stringify(data["@odata.nextLink"])), + (data["@odata.nextLink"] = dataStr.split("/v8.2/")[1])); + return res.status(200).json(data); }) .catch(({ err }) => { res.status(400).json(err); diff --git a/pages/api/endpoint/getformdata_api.js b/pages/api/endpoint/getformdata_api.js new file mode 100644 index 00000000..2900cb78 --- /dev/null +++ b/pages/api/endpoint/getformdata_api.js @@ -0,0 +1,43 @@ +import axios from "axios"; +import https from "https"; +import CryptoJS from "crypto-js"; +import { getToken, azureHeadersPaged, azureHeaders } 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 whichForm = req.query.whichForm; + var token = await getToken(); + + var queryUrl = + "systemforms?$select=formid,name,formxml,type,objecttypecode&$filter=(objecttypecode eq 'pinswg_" + + whichForm + + "' and type eq 2)&$count=true&$top=201"; + + return axios + .get( + WEBAPI_URL + queryUrl + hashAPIPath(queryUrl), + azureHeaders(token.access_token) + ) + .then(({ data }) => { + res.status(200).json(data); + }) + .catch(({ err }) => { + res.status(400).json(err); + }); +} diff --git a/pages/api/endpoint/getlpa_api.js b/pages/api/endpoint/getlpa_api.js index 1d79aeb3..d05a2feb 100644 --- a/pages/api/endpoint/getlpa_api.js +++ b/pages/api/endpoint/getlpa_api.js @@ -21,13 +21,16 @@ const hashAPIPath = (queryPath) => { }; export default async function ApiProxy(req, res) { - var token = req.query.token; + var token = await getToken(); 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)) + .get( + WEBAPI_URL + queryUrl + hashAPIPath(queryUrl), + azureHeaders(token.access_token) + ) .then(({ data }) => { res.status(200).json(data); }) diff --git a/pages/api/endpoint/getmandatoryfields_api.js b/pages/api/endpoint/getmandatoryfields_api.js new file mode 100644 index 00000000..c73ede95 --- /dev/null +++ b/pages/api/endpoint/getmandatoryfields_api.js @@ -0,0 +1,43 @@ +import axios from "axios"; +import https from "https"; +import CryptoJS from "crypto-js"; +import { getToken, azureHeadersPaged, azureHeaders } 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 whichForm = req.query.whichForm; + var token = await getToken(); + + var queryUrl = + "EntityDefinitions(LogicalName='pinswg_" + + whichForm + + "')/Attributes?$count=true&$select=LogicalName,RequiredLevel"; + + return axios + .get( + WEBAPI_URL + queryUrl + hashAPIPath(queryUrl), + azureHeaders(token.access_token) + ) + .then(({ data }) => { + res.status(200).json(data); + }) + .catch(({ err }) => { + res.status(400).json(err); + }); +} diff --git a/pages/api/endpoint/getmycases_api.js b/pages/api/endpoint/getmycases_api.js index 8271015f..64abd670 100644 --- a/pages/api/endpoint/getmycases_api.js +++ b/pages/api/endpoint/getmycases_api.js @@ -19,7 +19,7 @@ const hashAPIPath = (queryPath) => { export default async function ApiProxy(req, res) { var loggedInUserId = req.query.loggedInUserId; - var token = req.query.token; + var token = await getToken(); var queryUrl = "incidents?$select=ticketnumber,casetypecode,createdon,_customerid_value,description,incidentid,pinswg_appealcasetype,_pinswg_assignedinspectrids_value,statecode,statuscode,title&$filter=_customerid_value eq " + @@ -27,7 +27,10 @@ export default async function ApiProxy(req, res) { " and pinswg_appealcasetype ne null&$orderby=createdon desc&$count=true&$top=3"; return axios - .get(WEBAPI_URL + queryUrl + hashAPIPath(queryUrl), azureHeaders(token)) + .get( + WEBAPI_URL + queryUrl + hashAPIPath(queryUrl), + azureHeaders(token.access_token) + ) .then(({ data }) => { res.status(200).json(data); }) diff --git a/pages/api/endpoint/getmyrepresentations_api.js b/pages/api/endpoint/getmyrepresentations_api.js index b8d25b34..0851b9cc 100644 --- a/pages/api/endpoint/getmyrepresentations_api.js +++ b/pages/api/endpoint/getmyrepresentations_api.js @@ -19,7 +19,7 @@ const hashAPIPath = (queryPath) => { export default async function ApiProxy(req, res) { var loggedInUserId = req.query.loggedInUserId; - var token = req.query.token; + var token = await getToken(); var queryUrl = "pinswg_representationses?$filter= _pinswg_contact_value eq " + @@ -27,7 +27,10 @@ export default async function ApiProxy(req, res) { "&$count=true&$orderby=createdon desc"; return axios - .get(WEBAPI_URL + queryUrl + hashAPIPath(queryUrl), azureHeaders(token)) + .get( + WEBAPI_URL + queryUrl + hashAPIPath(queryUrl), + azureHeaders(token.access_token) + ) .then(({ data }) => { res.status(200).json(data); }) diff --git a/pages/api/endpoint/getmyrepresentationsproxy_api.js b/pages/api/endpoint/getmyrepresentationsproxy_api.js index b8d25b34..0851b9cc 100644 --- a/pages/api/endpoint/getmyrepresentationsproxy_api.js +++ b/pages/api/endpoint/getmyrepresentationsproxy_api.js @@ -19,7 +19,7 @@ const hashAPIPath = (queryPath) => { export default async function ApiProxy(req, res) { var loggedInUserId = req.query.loggedInUserId; - var token = req.query.token; + var token = await getToken(); var queryUrl = "pinswg_representationses?$filter= _pinswg_contact_value eq " + @@ -27,7 +27,10 @@ export default async function ApiProxy(req, res) { "&$count=true&$orderby=createdon desc"; return axios - .get(WEBAPI_URL + queryUrl + hashAPIPath(queryUrl), azureHeaders(token)) + .get( + WEBAPI_URL + queryUrl + hashAPIPath(queryUrl), + azureHeaders(token.access_token) + ) .then(({ data }) => { res.status(200).json(data); }) diff --git a/pages/api/endpoint/getpersonalaccount_api.js b/pages/api/endpoint/getpersonalaccount_api.js index b109ca1d..abd8d54d 100644 --- a/pages/api/endpoint/getpersonalaccount_api.js +++ b/pages/api/endpoint/getpersonalaccount_api.js @@ -19,7 +19,7 @@ const hashAPIPath = (queryPath) => { export default async function ApiProxy(req, res) { var contactid = req.query.contactid; - var token = req.query.token; + var token = await getToken(); var queryUrl = "contacts(" + @@ -27,7 +27,10 @@ export default async function ApiProxy(req, res) { ")?$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)) + .get( + WEBAPI_URL + queryUrl + hashAPIPath(queryUrl), + azureHeaders(token.access_token) + ) .then(({ data }) => { res.status(200).json(data); }) diff --git a/pages/api/endpoint/getpicklists_api.js b/pages/api/endpoint/getpicklists_api.js new file mode 100644 index 00000000..c741901b --- /dev/null +++ b/pages/api/endpoint/getpicklists_api.js @@ -0,0 +1,40 @@ +import axios from "axios"; +import https from "https"; +import CryptoJS from "crypto-js"; +import { getToken, azureHeaders } 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 (queryPath.indexOf("?") > -1 ? "&hash=" : "?hash=") + hashlink; +}; + +export default async function ApiProxy(req, res) { + var whichForm = req.query.whichForm; + var token = await getToken(); + + 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.access_token) + ) + .then(({ data }) => { + res.status(200).json(data); + }) + .catch(({ err }) => { + res.status(400).json(err); + }); +} diff --git a/pages/api/endpoint/getportalmoduledetails_api.js b/pages/api/endpoint/getportalmoduledetails_api.js index 37c4c192..655d861f 100644 --- a/pages/api/endpoint/getportalmoduledetails_api.js +++ b/pages/api/endpoint/getportalmoduledetails_api.js @@ -20,7 +20,7 @@ const hashAPIPath = (queryPath) => { export default async function ApiProxy(req, res) { var appealType = req.query.appealType; var caseReference = req.query.caseReference; - var token = req.query.token; + var token = await getToken(); var queryUrl = appealType + @@ -29,7 +29,10 @@ export default async function ApiProxy(req, res) { "'&$count=true"; return axios - .get(WEBAPI_URL + queryUrl + hashAPIPath(queryUrl), azureHeaders(token)) + .get( + WEBAPI_URL + queryUrl + hashAPIPath(queryUrl), + azureHeaders(token.access_token) + ) .then(({ data }) => { res.status(200).json(data); }) diff --git a/pages/api/endpoint/getrepresentationsproxy_api.js b/pages/api/endpoint/getrepresentationsproxy_api.js index b92286f7..67b0816a 100644 --- a/pages/api/endpoint/getrepresentationsproxy_api.js +++ b/pages/api/endpoint/getrepresentationsproxy_api.js @@ -19,7 +19,7 @@ const hashAPIPath = (queryPath) => { export default async function ApiProxy(req, res) { var incidentID = req.query.incidentID; - var token = req.query.token; + var token = await getToken(); var queryUrl = "pinswg_representationses?$filter= _pinswg_case_value eq " + @@ -27,7 +27,10 @@ export default async function ApiProxy(req, res) { "&$count=true&$orderby=createdon desc"; return axios - .get(WEBAPI_URL + queryUrl + hashAPIPath(queryUrl), azureHeaders(token)) + .get( + WEBAPI_URL + queryUrl + hashAPIPath(queryUrl), + azureHeaders(token.access_token) + ) .then(({ data }) => { res.status(200).json(data); }) diff --git a/pages/api/endpoint/getsearchdocumentdetails_api.js b/pages/api/endpoint/getsearchdocumentdetails_api.js index 8ce7c392..cfc71f4f 100644 --- a/pages/api/endpoint/getsearchdocumentdetails_api.js +++ b/pages/api/endpoint/getsearchdocumentdetails_api.js @@ -1,6 +1,7 @@ import axios from "axios"; import https from "https"; import CryptoJS from "crypto-js"; +import _ from "lodash"; import { getToken, azureHeadersPaged } from "../../../actions"; const WORDKEY = process.env.HASHKEY; @@ -54,7 +55,10 @@ export default async function ApiProxy(req, res) { element.pinswg_isharedocumentreference ); }); - //console.log("details data:", data); + var dataStr; + _.has(data, "@odata.nextLink") == true && + ((dataStr = JSON.stringify(data["@odata.nextLink"])), + (data["@odata.nextLink"] = dataStr.split("/v8.2/")[1])); res.status(200).json(data); }) diff --git a/pages/api/endpoint/getsearchdocumentdetailspaged_api.js b/pages/api/endpoint/getsearchdocumentdetailspaged_api.js index 480390aa..bba24ae7 100644 --- a/pages/api/endpoint/getsearchdocumentdetailspaged_api.js +++ b/pages/api/endpoint/getsearchdocumentdetailspaged_api.js @@ -1,6 +1,7 @@ import axios from "axios"; import https from "https"; import CryptoJS from "crypto-js"; +import _ from "lodash"; import { getToken, azureHeadersPaged } from "../../../actions"; const WORDKEY = process.env.HASHKEY; @@ -58,8 +59,11 @@ export default async function ApiProxy(req, res) { element.pinswg_isharedocumentreference ); }); - //console.log("details paged data:", data); - res.status(200).json(data); + var dataStr; + _.has(data, "@odata.nextLink") == true && + ((dataStr = JSON.stringify(data["@odata.nextLink"])), + (data["@odata.nextLink"] = dataStr.split("/v8.2/")[1])); + return res.status(200).json(data); }) .catch(({ err }) => { res.status(400).json(err); diff --git a/pages/api/endpoint/getwatchedcases_api copy 2.js b/pages/api/endpoint/getwatchedcases_api copy 2.js index cd7d502c..b9dda1ae 100644 --- a/pages/api/endpoint/getwatchedcases_api copy 2.js +++ b/pages/api/endpoint/getwatchedcases_api copy 2.js @@ -19,7 +19,7 @@ const hashAPIPath = (queryPath) => { export default async function ApiProxy(req, res) { var loggedInUserId = req.query.loggedInUserId; - var token = req.query.token; + var token = await getToken(); var queryUrl = "pinswg_watchlists?$filter= _pinswg_contact_value eq " + @@ -27,7 +27,10 @@ export default async function ApiProxy(req, res) { "&$count=true&$orderby=createdon desc"; return axios - .get(WEBAPI_URL + queryUrl + hashAPIPath(queryUrl), azureHeaders(token)) + .get( + WEBAPI_URL + queryUrl + hashAPIPath(queryUrl), + azureHeaders(token.access_token) + ) .then(({ data }) => { res.status(200).json(data); }) diff --git a/pages/api/endpoint/getwatchedcases_api.js b/pages/api/endpoint/getwatchedcases_api.js index cd7d502c..b9dda1ae 100644 --- a/pages/api/endpoint/getwatchedcases_api.js +++ b/pages/api/endpoint/getwatchedcases_api.js @@ -19,7 +19,7 @@ const hashAPIPath = (queryPath) => { export default async function ApiProxy(req, res) { var loggedInUserId = req.query.loggedInUserId; - var token = req.query.token; + var token = await getToken(); var queryUrl = "pinswg_watchlists?$filter= _pinswg_contact_value eq " + @@ -27,7 +27,10 @@ export default async function ApiProxy(req, res) { "&$count=true&$orderby=createdon desc"; return axios - .get(WEBAPI_URL + queryUrl + hashAPIPath(queryUrl), azureHeaders(token)) + .get( + WEBAPI_URL + queryUrl + hashAPIPath(queryUrl), + azureHeaders(token.access_token) + ) .then(({ data }) => { res.status(200).json(data); })