update query to get ticketnumber using navigationproproperty
This commit is contained in:
@@ -34,6 +34,15 @@ export const getFormCollectionByID = (appealTypeID) => {
|
|||||||
return collectionName[0];
|
return collectionName[0];
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const getNavigationPropertyByPrimaryAttribute = (primaryAttribute) => {
|
||||||
|
const collectionName = jsonpath({
|
||||||
|
path: "$..[?(@ && @.PrimaryIdAttribute =='" + primaryAttribute + "')]",
|
||||||
|
json: data,
|
||||||
|
eval: true,
|
||||||
|
});
|
||||||
|
return collectionName[0];
|
||||||
|
};
|
||||||
|
|
||||||
export const getFormIDByLogicalName = (appealTypeLogicalName) => {
|
export const getFormIDByLogicalName = (appealTypeLogicalName) => {
|
||||||
const collectionName = jsonpath({
|
const collectionName = jsonpath({
|
||||||
path: "$..[?(@ && @.LogicalName =='" + appealTypeLogicalName + "')]",
|
path: "$..[?(@ && @.LogicalName =='" + appealTypeLogicalName + "')]",
|
||||||
|
|||||||
@@ -33,7 +33,7 @@ import axios from "axios";
|
|||||||
import CryptoJS from "crypto-js";
|
import CryptoJS from "crypto-js";
|
||||||
import { azureHeaders, consoleLogger, getToken } from "../../../actions";
|
import { azureHeaders, consoleLogger, getToken } from "../../../actions";
|
||||||
import { getSelectQuery } from "../../../actions/selectQueryTypes";
|
import { getSelectQuery } from "../../../actions/selectQueryTypes";
|
||||||
|
import { getNavigationPropertyByPrimaryAttribute } from "../../../components/utils";
|
||||||
const WORDKEY = process.env.HASHKEY;
|
const WORDKEY = process.env.HASHKEY;
|
||||||
|
|
||||||
const WEBAPI_URL =
|
const WEBAPI_URL =
|
||||||
@@ -55,13 +55,22 @@ export default async function ApiProxy(req, res) {
|
|||||||
var incidentID = req.query.incidentID;
|
var incidentID = req.query.incidentID;
|
||||||
var token = await getToken();
|
var token = await getToken();
|
||||||
|
|
||||||
|
let navigationProperty =
|
||||||
|
getNavigationPropertyByPrimaryAttribute(
|
||||||
|
primaryIdAttribute
|
||||||
|
).NavigationProperty;
|
||||||
|
|
||||||
var queryUrl =
|
var queryUrl =
|
||||||
appealTypeName +
|
appealTypeName +
|
||||||
"?$filter=_" +
|
"?$filter=_" +
|
||||||
primaryIdAttribute +
|
primaryIdAttribute +
|
||||||
"s_value eq " +
|
"s_value eq " +
|
||||||
incidentID +
|
incidentID +
|
||||||
"&$count=true";
|
"&$count=true" +
|
||||||
|
"&$expand=" +
|
||||||
|
navigationProperty +
|
||||||
|
"($select=ticketnumber)";
|
||||||
|
|
||||||
//" and statuscode eq 1&$count=true";
|
//" and statuscode eq 1&$count=true";
|
||||||
|
|
||||||
queryUrl = queryUrl + getSelectQuery(appealTypeName);
|
queryUrl = queryUrl + getSelectQuery(appealTypeName);
|
||||||
@@ -81,6 +90,13 @@ export default async function ApiProxy(req, res) {
|
|||||||
azureHeaders(token.access_token)
|
azureHeaders(token.access_token)
|
||||||
)
|
)
|
||||||
.then(({ data }) => {
|
.then(({ data }) => {
|
||||||
|
let flattened = data.value.map((r) => ({
|
||||||
|
...r,
|
||||||
|
ticketnumber: r[navigationProperty]?.ticketnumber || null,
|
||||||
|
}));
|
||||||
|
|
||||||
|
data.value = flattened;
|
||||||
|
|
||||||
res.status(200).json(data);
|
res.status(200).json(data);
|
||||||
})
|
})
|
||||||
.catch((error) => {
|
.catch((error) => {
|
||||||
|
|||||||
@@ -34,7 +34,7 @@ import CryptoJS from "crypto-js";
|
|||||||
import _ from "lodash";
|
import _ from "lodash";
|
||||||
import { azureHeadersPaged, consoleLogger, getToken } from "../../../actions";
|
import { azureHeadersPaged, consoleLogger, getToken } from "../../../actions";
|
||||||
import { getSelectQuery } from "../../../actions/selectQueryTypes";
|
import { getSelectQuery } from "../../../actions/selectQueryTypes";
|
||||||
|
import { getNavigationPropertyByPrimaryAttribute } from "../../../components/utils";
|
||||||
const WORDKEY = process.env.HASHKEY;
|
const WORDKEY = process.env.HASHKEY;
|
||||||
|
|
||||||
const WEBAPI_URL =
|
const WEBAPI_URL =
|
||||||
@@ -59,13 +59,22 @@ export default async function ApiProxy(req, res) {
|
|||||||
var incidentID = req.query.incidentID;
|
var incidentID = req.query.incidentID;
|
||||||
var token = await getToken();
|
var token = await getToken();
|
||||||
|
|
||||||
|
let navigationProperty =
|
||||||
|
getNavigationPropertyByPrimaryAttribute(
|
||||||
|
primaryIdAttribute
|
||||||
|
).NavigationProperty;
|
||||||
|
|
||||||
var queryUrl =
|
var queryUrl =
|
||||||
appealTypeName +
|
appealTypeName +
|
||||||
"?$filter=_" +
|
"?$filter=_" +
|
||||||
primaryIdAttribute +
|
primaryIdAttribute +
|
||||||
"s_value eq " +
|
"s_value eq " +
|
||||||
incidentID +
|
incidentID +
|
||||||
"&$count=true";
|
"&$count=true" +
|
||||||
|
"&$expand=" +
|
||||||
|
navigationProperty +
|
||||||
|
"($select=ticketnumber)";
|
||||||
|
|
||||||
//" and statuscode eq 1&$count=true";
|
//" and statuscode eq 1&$count=true";
|
||||||
|
|
||||||
queryUrl = queryUrl + getSelectQuery(appealTypeName);
|
queryUrl = queryUrl + getSelectQuery(appealTypeName);
|
||||||
@@ -78,10 +87,18 @@ export default async function ApiProxy(req, res) {
|
|||||||
azureHeadersPaged(token.access_token)
|
azureHeadersPaged(token.access_token)
|
||||||
)
|
)
|
||||||
.then(({ data }) => {
|
.then(({ data }) => {
|
||||||
|
let flattened = data.value.map((r) => ({
|
||||||
|
...r,
|
||||||
|
ticketnumber: r[navigationProperty]?.ticketnumber || null,
|
||||||
|
}));
|
||||||
|
|
||||||
|
data.value = flattened;
|
||||||
|
|
||||||
var dataStr;
|
var dataStr;
|
||||||
_.has(data, "@odata.nextLink") == true &&
|
_.has(data, "@odata.nextLink") == true &&
|
||||||
((dataStr = JSON.stringify(data["@odata.nextLink"])),
|
((dataStr = JSON.stringify(data["@odata.nextLink"])),
|
||||||
(data["@odata.nextLink"] = dataStr.split("/v8.2/")[1]));
|
(data["@odata.nextLink"] = dataStr.split("/v8.2/")[1]));
|
||||||
|
|
||||||
return res.status(200).json(data);
|
return res.status(200).json(data);
|
||||||
})
|
})
|
||||||
.catch((error) => {
|
.catch((error) => {
|
||||||
|
|||||||
Reference in New Issue
Block a user