added fixes to reduce error when calling module details and filtering of docs
This commit is contained in:
@@ -25,9 +25,17 @@ export default async function ApiProxy(req, res) {
|
||||
var token = await getToken();
|
||||
|
||||
var queryUrl =
|
||||
"incidents?$select=_customerid_value,_pinswg_associatedlpa_value,_ownerid_value,statuscode,ticketnumber,title &$filter=pinswg_appealcasetype eq 846040011 and pinswg_publishtoweb eq true&$orderby=createdon desc&$count=true";
|
||||
"incidents?$select=pinswg_appealcasetype,_customerid_value,_pinswg_associatedlpa_value,_ownerid_value,statuscode,ticketnumber,title &$filter=pinswg_appealcasetype eq 846040011 and pinswg_publishtoweb eq true&$orderby=createdon desc&$count=true";
|
||||
|
||||
//console.log(queryUrl);
|
||||
console.log(queryUrl);
|
||||
|
||||
function renameJsonKey(jsonObj, oldKey, newKey) {
|
||||
if (jsonObj.hasOwnProperty(oldKey)) {
|
||||
jsonObj[newKey] = jsonObj[oldKey]; // Add new key with the same value
|
||||
delete jsonObj[oldKey]; // Delete old key
|
||||
}
|
||||
return jsonObj;
|
||||
}
|
||||
|
||||
return axios
|
||||
.get(
|
||||
@@ -36,6 +44,7 @@ export default async function ApiProxy(req, res) {
|
||||
)
|
||||
.then(({ data }) => {
|
||||
var dataStr;
|
||||
|
||||
_.has(data, "@odata.nextLink") == true &&
|
||||
((dataStr = JSON.stringify(data["@odata.nextLink"])),
|
||||
(data["@odata.nextLink"] = dataStr.split("/v8.2/")[1]));
|
||||
|
||||
@@ -38,27 +38,33 @@ const hashAPIPath = (queryPath) => {
|
||||
return (queryPath.indexOf("?") > -1 ? "&hash=" : "?hash=") + hashlink;
|
||||
};
|
||||
|
||||
const groupArray = (arr = []) => {
|
||||
// create map
|
||||
let map = new Map();
|
||||
for (let i = 0; i < arr.length; i++) {
|
||||
const s = JSON.stringify(arr[i]);
|
||||
if (!map.has(s)) {
|
||||
map.set(s, {
|
||||
pinswg_isharedocumentlocations:
|
||||
arr[i].pinswg_isharedocumentlocations,
|
||||
pinswg_isharedocumentlocationsLabel:
|
||||
arr[i][
|
||||
"pinswg_isharedocumentlocations@OData.Community.Display.V1.FormattedValue"
|
||||
],
|
||||
// count: 1,
|
||||
});
|
||||
} else {
|
||||
//map.get(s).count++;
|
||||
}
|
||||
}
|
||||
const res = Array.from(map.values());
|
||||
return res;
|
||||
const groupArray = (arr) => {
|
||||
const map = new Map();
|
||||
|
||||
// Count occurrences of each object
|
||||
arr.forEach((obj) => {
|
||||
const key = JSON.stringify(obj);
|
||||
map.set(key, (map.get(key) || 0) + 1);
|
||||
});
|
||||
|
||||
// Create a new array to store unique objects with count
|
||||
const result = [];
|
||||
map.forEach((count, key) => {
|
||||
const obj = JSON.parse(key);
|
||||
|
||||
const transformedObj = {
|
||||
pinswg_isharedocumentlocations: obj.pinswg_isharedocumentlocations, // Change 'id' to 'userId'
|
||||
pinswg_isharedocumentlocationsLabel:
|
||||
obj[
|
||||
"pinswg_isharedocumentlocations@OData.Community.Display.V1.FormattedValue"
|
||||
], // Change 'name' to 'userName'
|
||||
count: count, // Add 'count' as 'occurrences'
|
||||
};
|
||||
|
||||
result.push(transformedObj);
|
||||
});
|
||||
|
||||
return result;
|
||||
};
|
||||
|
||||
export default async function ApiProxy(req, res) {
|
||||
|
||||
@@ -92,6 +92,37 @@ export default async function ApiProxy(req, res) {
|
||||
var showNumberOfRecords = req.query.showNumberOfRecords;
|
||||
var documentType = req.query.documentType || "all";
|
||||
|
||||
// (documentType != "all"
|
||||
// ? documentType.indexOf(",")<0?" and pinswg_isharedocumentlocations eq " + documentType :
|
||||
// : "") +
|
||||
|
||||
var docTypeQueryString = "";
|
||||
|
||||
if (documentType != "all") {
|
||||
if (documentType.indexOf(",") >= 0) {
|
||||
const documentTypeArr = documentType.split(",");
|
||||
|
||||
docTypeQueryString = " and (";
|
||||
documentTypeArr.forEach(function (item, index) {
|
||||
console.log(item, index);
|
||||
|
||||
if (item != "all") {
|
||||
docTypeQueryString +=
|
||||
" pinswg_isharedocumentlocations eq " + item;
|
||||
|
||||
docTypeQueryString +=
|
||||
index < documentTypeArr.length - 1 ? " or " : "";
|
||||
}
|
||||
});
|
||||
docTypeQueryString += " )";
|
||||
} else {
|
||||
docTypeQueryString +=
|
||||
" and pinswg_isharedocumentlocations eq " + documentType;
|
||||
}
|
||||
}
|
||||
|
||||
console.log(docTypeQueryString);
|
||||
|
||||
//console.log("has this passed docuemntType:", documentType);
|
||||
//(documentType !="all" && " pinswg_pinswg_isharedocumentlocations eq " + )
|
||||
|
||||
@@ -99,9 +130,7 @@ export default async function ApiProxy(req, res) {
|
||||
"pinswg_documents?$filter=pinswg_publishtoweb eq true and _pinswg_documentids_value eq " +
|
||||
incidentID +
|
||||
" and pinswg_latestpublishedversion ne null and pinswg_latestpublisheddate ne null" +
|
||||
(documentType != "all"
|
||||
? " and pinswg_isharedocumentlocations eq " + documentType
|
||||
: "") +
|
||||
docTypeQueryString +
|
||||
"&$select=pinswg_isharedocumentlocations,_pinswg_documentids_value,pinswg_isharelabelcasetype,pinswg_isharelabellpaname,pinswg_publishtoweb,pinswg_uploadstatus,pinswg_isharedocumentclassification,pinswg_isharedocumentreference,pinswg_name,pinswg_latestpublishedversion,pinswg_latestpublisheddate&$orderby=" +
|
||||
orderby +
|
||||
" " +
|
||||
@@ -111,7 +140,7 @@ export default async function ApiProxy(req, res) {
|
||||
? "&$skiptoken=" + ('<cookie pagenumber="' + pageNumber + '" />')
|
||||
: "");
|
||||
|
||||
//console.log("docu paged: ", queryUrl);
|
||||
console.log("docu paged: ", queryUrl);
|
||||
|
||||
return axios
|
||||
.get(
|
||||
|
||||
Reference in New Issue
Block a user