update query to get ticketnumber using navigationproproperty
This commit is contained in:
@@ -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 + "')]",
|
||||
|
||||
@@ -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) => {
|
||||
|
||||
@@ -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) => {
|
||||
|
||||
Reference in New Issue
Block a user