From 95b6137cbc75e165a5fe811854e465c1085ac239 Mon Sep 17 00:00:00 2001 From: rdbsolutions Date: Fri, 1 Nov 2024 14:26:55 +0000 Subject: [PATCH] added in debug and async some calls --- actions/index.js | 18 +++++ components/case/summary.js | 2 +- components/utils/index.js | 31 +++++++-- pages/advancedsearchresults.js | 14 +++- pages/api/file/createcaseinvolvement_api.js | 76 +++++++++++++++++++++ 5 files changed, 132 insertions(+), 9 deletions(-) create mode 100644 pages/api/file/createcaseinvolvement_api.js diff --git a/actions/index.js b/actions/index.js index f89d84d3..cdb7c72f 100644 --- a/actions/index.js +++ b/actions/index.js @@ -1942,6 +1942,24 @@ export const setRepInvolvment = async (caseid, contactid) => { } }; +export const setCaseInvolvment = async (caseid, contactid) => { + var queryUrl = "/api/file/createrepinvolvement_api"; + + var data = { "incidentid": caseid, "contactid": contactid }; + var config = { + method: "post", + url: queryUrl, + data: data, + }; + + try { + const res = await axios(config); + return res.data; + } catch (error) { + consoleLogger(error); + } +}; + export const getAddressSearch = async (searchString) => { const params = new URLSearchParams(searchString); const str = params.toString(); diff --git a/components/case/summary.js b/components/case/summary.js index fa070a61..44771adb 100644 --- a/components/case/summary.js +++ b/components/case/summary.js @@ -148,7 +148,7 @@ const CaseSummary = (props) => { : props[currentType]; let setCaseDetailsObj = currentType == "directResultsObj" - ? props.searchDetailsObj + ? props.searchResultsObj.searchDetailsObj : props[currentType + "Details"]; var casesObj = {}; diff --git a/components/utils/index.js b/components/utils/index.js index 14c05868..d0ed99b0 100644 --- a/components/utils/index.js +++ b/components/utils/index.js @@ -69,11 +69,22 @@ export const getRadioLabel = (data, radiotListName, radioListID) => { * Get the details of a case from the appeal type * @param object searchResultsObj */ -export const getSearchDetails = (searchResultsObj) => { +export const getSearchDetails = async (searchResultsObj) => { let detailsArr = []; searchResultsObj = searchResultsObj.value; const detailsObj = searchResultsObj.map((searchDetail, index) => { + let formMeta = getFormCollectionByID( + searchDetail.pinswg_appealcasetype + ); + console.log( + "------------------- Details: ", + formMeta.LogicalCollectionName, + searchDetail.title, + formMeta.PrimaryIdAttribute, + searchDetail.incidentid + ); + if (searchDetail.pinswg_appealcasetype == null) { detailsArr.push( getBasicSearchDetails( @@ -81,22 +92,30 @@ export const getSearchDetails = (searchResultsObj) => { searchDetail.title, "pinswg_dnsid", searchDetail.incidentid - ) + ) || { + "@odata.count": 1, + "value": [{ "title": searchDetail.title }], + } ); } else { - let formMeta = getFormCollectionByID( - searchDetail.pinswg_appealcasetype - ); detailsArr.push( getBasicSearchDetails( formMeta.LogicalCollectionName, searchDetail.title, formMeta.PrimaryIdAttribute, searchDetail.incidentid - ) + ) || { + "@odata.count": 1, + "value": [{ "title": searchDetail.title }], + } ); } }); + // Promise.all(detailsArr).then((data) => { + // console.log(data); + // console.log(detailsArr); + // return data; + // }); return Promise.all(detailsArr); }; diff --git a/pages/advancedsearchresults.js b/pages/advancedsearchresults.js index a204674e..0709b84c 100644 --- a/pages/advancedsearchresults.js +++ b/pages/advancedsearchresults.js @@ -117,10 +117,20 @@ export const getServerSideProps = wrapper.getServerSideProps( (store) => async ({ query, req, res }) => { console.log("query-", query); - //console.log("search array:", Object.entries(query)); + console.log("search array:", Object.entries(query)); const searchResultsObj = await getAdvancedSearch(query); - const searchDetailsObj = await getSearchDetails(searchResultsObj); + console.log( + "=============================== Advanced Search results:", + searchResultsObj + ); + const searchDetailsObj = + (await getSearchDetails(searchResultsObj)) || null; + console.log( + "=============================== Advanced Search results details:", + searchDetailsObj + ); + const showLoginCheck = process.env.SHOWLOGIN || false; const showReps = process.env.SHOWREPRESENTATIONS || false; store.dispatch(setShowReps(showReps, showLoginCheck)); diff --git a/pages/api/file/createcaseinvolvement_api.js b/pages/api/file/createcaseinvolvement_api.js new file mode 100644 index 00000000..545f34ea --- /dev/null +++ b/pages/api/file/createcaseinvolvement_api.js @@ -0,0 +1,76 @@ +/** + * @swagger + * /api/endpoint/createmywatchedcases_api: + * post: + * tags: [Portal,Case] + * summary: Phase 2 + * description: Create my watched cases + * responses: + * 200: + * description: Success + */ + +import axios from "axios"; +import CryptoJS from "crypto-js"; +import { consoleLogger, getToken } 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 token = await getToken(); + var contactid = req.body.contactid; + var queryUrl = + "incidents(" + + req.body.incidentid + + ")/pinswg_incident_contact_case_involvement/$ref"; + + console.log(req.body, queryUrl); + + var crmUrl = "https://" + process.env.CRMURL; + + var data = { + "@odata.id": crmUrl + "/api/data/v8.2/contacts(" + contactid + ")", + }; + + var config = { + method: "post", + url: WEBAPI_URL + queryUrl + hashAPIPath(queryUrl), + headers: { + "OData-MaxVersion": "4.0", + "OData-Version": "4.0", + "Accept": "application/json", + "If-None-Match": "null", + "Prefer": 'odata.include-annotations="*",return=representation', + "Authorization": "Bearer " + token.access_token, + "Content-Type": "application/json", + }, + data: data, + }; + + return axios(config) + .then(({ data }) => { + res.status(200).json(data); + }) + .catch((error) => { + return error.status == 412 + ? res.status(200).json({ "record": "exists" }) + : (consoleLogger(Object.assign(error, data)), + res.status(400).json(error)); + }); +}