partial synch with ph2 updates
This commit is contained in:
+59
-21
@@ -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 + "')]",
|
||||
@@ -170,29 +179,58 @@ export const getPartSavedDetails = (searchResultsObj) => {
|
||||
* Get the details of a case from the appeal type
|
||||
* @param object searchResultsObj
|
||||
*/
|
||||
export const getSearchDetailsPaged = (searchResultsObj) => {
|
||||
let detailsArr = [];
|
||||
export const getSearchDetailsPaged = async (searchResultsObj) => {
|
||||
searchResultsObj = searchResultsObj.value;
|
||||
const detailsObj = searchResultsObj.map((searchDetail, index) => {
|
||||
if (searchDetail.pinswg_appealcasetype == null) {
|
||||
console.log(searchDetail.title);
|
||||
} else {
|
||||
let formMeta = getFormCollectionByID(
|
||||
searchDetail.pinswg_appealcasetype
|
||||
);
|
||||
// formMeta?.LogicalCollectionName &&
|
||||
// formMeta?.LogicalCollectionName != "pinswg_sipses" &&
|
||||
detailsArr.push(
|
||||
getBasicSearchDetailsPaged(
|
||||
formMeta.LogicalCollectionName,
|
||||
searchDetail.title,
|
||||
formMeta.PrimaryIdAttribute,
|
||||
searchDetail.incidentid
|
||||
)
|
||||
);
|
||||
|
||||
// Group incidents by appeal type
|
||||
const groupedByAppealType = searchResultsObj.reduce((acc, detail) => {
|
||||
const appealType = detail.pinswg_appealcasetype;
|
||||
if (!appealType) {
|
||||
console.log("No appeal type for:", detail.title);
|
||||
return acc;
|
||||
}
|
||||
});
|
||||
return Promise.all(detailsArr);
|
||||
|
||||
if (!acc[appealType]) acc[appealType] = [];
|
||||
acc[appealType].push({
|
||||
incidentID: detail.incidentid,
|
||||
title: detail.title,
|
||||
});
|
||||
return acc;
|
||||
}, {});
|
||||
|
||||
const allDetails = [];
|
||||
|
||||
// For each appeal type, call getBasicSearchDetailsPaged once with all incident IDs
|
||||
for (const [appealType, incidents] of Object.entries(groupedByAppealType)) {
|
||||
const incidentIDs = incidents.map((i) => i.incidentID);
|
||||
|
||||
// Get the form meta for this appeal type to access primaryIdAttribute
|
||||
const formMeta = getFormCollectionByID(appealType);
|
||||
|
||||
if (!formMeta || !formMeta.PrimaryIdAttribute) {
|
||||
console.log(`Missing form metadata for appeal type: ${appealType}`);
|
||||
continue;
|
||||
}
|
||||
|
||||
// console.log(
|
||||
// `Fetching ${incidentIDs.length} incidents for appeal type: ${appealType} with primaryIdAttribute: ${formMeta.PrimaryIdAttribute}`
|
||||
// );
|
||||
|
||||
try {
|
||||
const details = await getBasicSearchDetailsPaged(
|
||||
formMeta.LogicalCollectionName, // appealTypeName
|
||||
null, // caseReference is no longer used in batch
|
||||
formMeta.PrimaryIdAttribute, // primaryIdAttribute
|
||||
incidentIDs // pass array of incidentIDs
|
||||
);
|
||||
|
||||
allDetails.push(...details);
|
||||
} catch (err) {
|
||||
consoleLogger(err);
|
||||
}
|
||||
}
|
||||
|
||||
return allDetails;
|
||||
};
|
||||
|
||||
// export const absoluteUrl = (req, setLocalhost) => {
|
||||
|
||||
Reference in New Issue
Block a user