diff --git a/components/utils/index.js b/components/utils/index.js index ba9b616c..eaef542b 100644 --- a/components/utils/index.js +++ b/components/utils/index.js @@ -34,6 +34,15 @@ export const getFormCollectionByID = (appealTypeID) => { return collectionName[0]; }; +export const getNavigationPropertyByPrimaryAttribute = (primaryAttribute) => { + const collectionName = jsonpath({ + path: "$..[?(@ && @.PrimaryIdAttribute =='" + primaryAttribute + "')]", + json: data, + eval: true, + }); + return collectionName[0]; +}; + export const getFormIDByLogicalName = (appealTypeLogicalName) => { const collectionName = jsonpath({ path: "$..[?(@ && @.LogicalName =='" + appealTypeLogicalName + "')]", diff --git a/pages/api/endpoint/getbasicsearchdetails_api.js b/pages/api/endpoint/getbasicsearchdetails_api.js index 83574a81..f33aeb65 100644 --- a/pages/api/endpoint/getbasicsearchdetails_api.js +++ b/pages/api/endpoint/getbasicsearchdetails_api.js @@ -33,7 +33,7 @@ import axios from "axios"; import CryptoJS from "crypto-js"; import { azureHeaders, consoleLogger, getToken } from "../../../actions"; import { getSelectQuery } from "../../../actions/selectQueryTypes"; - +import { getNavigationPropertyByPrimaryAttribute } from "../../../components/utils"; const WORDKEY = process.env.HASHKEY; const WEBAPI_URL = @@ -55,13 +55,22 @@ export default async function ApiProxy(req, res) { var incidentID = req.query.incidentID; var token = await getToken(); + let navigationProperty = + getNavigationPropertyByPrimaryAttribute( + primaryIdAttribute + ).NavigationProperty; + var queryUrl = appealTypeName + "?$filter=_" + primaryIdAttribute + "s_value eq " + incidentID + - "&$count=true"; + "&$count=true" + + "&$expand=" + + navigationProperty + + "($select=ticketnumber)"; + //" and statuscode eq 1&$count=true"; queryUrl = queryUrl + getSelectQuery(appealTypeName); @@ -81,6 +90,13 @@ export default async function ApiProxy(req, res) { azureHeaders(token.access_token) ) .then(({ data }) => { + let flattened = data.value.map((r) => ({ + ...r, + ticketnumber: r[navigationProperty]?.ticketnumber || null, + })); + + data.value = flattened; + res.status(200).json(data); }) .catch((error) => { diff --git a/pages/api/endpoint/getbasicsearchdetailspaged_api.js b/pages/api/endpoint/getbasicsearchdetailspaged_api.js index 544d42fb..b2acaa78 100644 --- a/pages/api/endpoint/getbasicsearchdetailspaged_api.js +++ b/pages/api/endpoint/getbasicsearchdetailspaged_api.js @@ -34,7 +34,7 @@ import CryptoJS from "crypto-js"; import _ from "lodash"; import { azureHeadersPaged, consoleLogger, getToken } from "../../../actions"; import { getSelectQuery } from "../../../actions/selectQueryTypes"; - +import { getNavigationPropertyByPrimaryAttribute } from "../../../components/utils"; const WORDKEY = process.env.HASHKEY; const WEBAPI_URL = @@ -59,13 +59,22 @@ export default async function ApiProxy(req, res) { var incidentID = req.query.incidentID; var token = await getToken(); + let navigationProperty = + getNavigationPropertyByPrimaryAttribute( + primaryIdAttribute + ).NavigationProperty; + var queryUrl = appealTypeName + "?$filter=_" + primaryIdAttribute + "s_value eq " + incidentID + - "&$count=true"; + "&$count=true" + + "&$expand=" + + navigationProperty + + "($select=ticketnumber)"; + //" and statuscode eq 1&$count=true"; queryUrl = queryUrl + getSelectQuery(appealTypeName); @@ -78,10 +87,18 @@ export default async function ApiProxy(req, res) { azureHeadersPaged(token.access_token) ) .then(({ data }) => { + let flattened = data.value.map((r) => ({ + ...r, + ticketnumber: r[navigationProperty]?.ticketnumber || null, + })); + + data.value = flattened; + 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((error) => {