TASK22224: complete documents + endpoint hygiene slices
This commit is contained in:
@@ -116,6 +116,8 @@ const WEBAPI_URL =
|
||||
process.env.RELAY_ROOT ||
|
||||
"https://dev-pedw-ns.servicebus.windows.net/dev-pedw-hc/";
|
||||
|
||||
const FILE_NOT_AVAILABLE_PATH = "/filenotavailable";
|
||||
|
||||
// Retry utility with logging
|
||||
async function retry(fn, retries = 3, delay = 1000) {
|
||||
for (let attempt = 1; attempt <= retries; attempt++) {
|
||||
@@ -133,6 +135,18 @@ async function retry(fn, retries = 3, delay = 1000) {
|
||||
const ApiProxy = async (req, res) => {
|
||||
const docRef = req.query;
|
||||
|
||||
if (
|
||||
typeof docRef?.id !== "string" ||
|
||||
docRef.id.length === 0 ||
|
||||
typeof docRef?.hash !== "string" ||
|
||||
docRef.hash.length === 0
|
||||
) {
|
||||
if (!res.headersSent) {
|
||||
res.redirect(FILE_NOT_AVAILABLE_PATH);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
const token = await getToken();
|
||||
const startTime = Date.now();
|
||||
@@ -186,11 +200,11 @@ const ApiProxy = async (req, res) => {
|
||||
|
||||
response.data.on("error", (err) => {
|
||||
consoleLogger(err);
|
||||
if (!res.headersSent) res.redirect("/filenotavailable");
|
||||
if (!res.headersSent) res.redirect(FILE_NOT_AVAILABLE_PATH);
|
||||
});
|
||||
} catch (error) {
|
||||
consoleLogger(error);
|
||||
if (!res.headersSent) res.redirect("/filenotavailable");
|
||||
if (!res.headersSent) res.redirect(FILE_NOT_AVAILABLE_PATH);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -20,35 +20,6 @@ const WEBAPI_URL =
|
||||
process.env.RELAY_ROOT ||
|
||||
"https://dev-pedw-ns.servicebus.windows.net/dev-pedw-hc/";
|
||||
|
||||
// export default async function ApiProxy(req, res) {
|
||||
// var token = await getToken();
|
||||
// var data = JSON.stringify(req.body);
|
||||
// var queryUrl = "pinswg_watchlists";
|
||||
|
||||
// console.log(data);
|
||||
// var config = {
|
||||
// method: "put",
|
||||
// url: WEBAPI_URL + queryUrl + hashAPIPath(queryUrl),
|
||||
// headers: {
|
||||
// "OData-MaxVersion": "4.0",
|
||||
// "OData-Version": "4.0",
|
||||
// "Accept": "application/json",
|
||||
// "Prefer": 'odata.include-annotations="*",return=representation',
|
||||
// "Authorization": "Bearer " + token.access_token,
|
||||
// "Content-Type": "application/json",
|
||||
// },
|
||||
// data: data,
|
||||
// };
|
||||
|
||||
// return axios(config)
|
||||
// .then(({ data }) => {
|
||||
// res.status(200).json(data);
|
||||
// })
|
||||
// .catch((error) => {
|
||||
// consoleLogger(Object.assign(err, data));
|
||||
// res.status(400).json(error);
|
||||
// });
|
||||
// }
|
||||
const recordExists = async (incidentId, contactId, token) => {
|
||||
const filter = `$filter=pinswg_WatchedCase/incidentid eq ${incidentId} and pinswg_Contact/contactid eq ${contactId}`;
|
||||
const queryUrl = `pinswg_watchlists?${filter}`;
|
||||
|
||||
@@ -258,161 +258,3 @@ export default async function ApiProxy(req, res) {
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
// export default async function ApiProxy(req, res) {
|
||||
// var searchString = req.query.searchstring;
|
||||
// var pageNumber = req.query.pageNumber;
|
||||
// var token = await getToken();
|
||||
|
||||
// var orderby = req.query.orderby;
|
||||
// var fieldSort = req.query.fieldSort;
|
||||
// var showNumberOfRecords = req.query.showNumberOfRecords;
|
||||
|
||||
// searchString = _.isEmpty(searchString)
|
||||
// ? searchString
|
||||
// : JSON.parse(decodeURI(searchString));
|
||||
|
||||
// var queryString = "";
|
||||
|
||||
// queryString +=
|
||||
// _.has(searchString, "q") && searchString.q != null
|
||||
// ? "(contains(title, '" +
|
||||
// searchString.q.replace(/\'/g, "''") +
|
||||
// "') or contains(ticketnumber,'" +
|
||||
// searchString.q.replace(/\'/g, "''") +
|
||||
// "')) and"
|
||||
// : "";
|
||||
|
||||
// queryString +=
|
||||
// (_.has(searchString, "lpa") || _.has(searchString, "LPA")) &&
|
||||
// searchString.lpa != null
|
||||
// ? " _pinswg_associatedlpa_value eq " + searchString.lpa + " and"
|
||||
// : "";
|
||||
|
||||
// queryString +=
|
||||
// _.has(searchString, "apt") && searchString.apt != null
|
||||
// ? " pinswg_appealcasetype eq " + searchString.apt + " and"
|
||||
// : "";
|
||||
|
||||
// queryString +=
|
||||
// _.has(searchString, "statuscode") && searchString.statuscode != null
|
||||
// ? " statuscode eq " + searchString.statuscode + " and"
|
||||
// : "";
|
||||
|
||||
// var queryUrl =
|
||||
// "incidents?$select=pinswg_environmentalstatementlocation,pinswg_caseaddress,modifiedon,description,numberofchildincidents,_accountid_value,_customerid_value,_pinswg_associatedlpa_value,_ownerid_value,pinswg_appealcasetype,statuscode,ticketnumber,title,_primarycontactid_value,pinswg_lpareference,pinswg_appellantagent,pinswg_appellantfirstname,pinswg_appellantlastname&$expand=primarycontactid($select=fullname)&$filter=" +
|
||||
// queryString +
|
||||
// " pinswg_appealcasetype ne null and pinswg_publishtoweb eq true&$orderby=" +
|
||||
// orderby +
|
||||
// " " +
|
||||
// fieldSort +
|
||||
// "&$count=true";
|
||||
|
||||
// console.log(WEBAPI_URL + queryUrl + hashAPIPath(queryUrl));
|
||||
|
||||
// var apiResponse = _.isEmpty(searchString)
|
||||
// ? res.status(400).json()
|
||||
// : axios
|
||||
// .get(
|
||||
// WEBAPI_URL + queryUrl + hashAPIPath(queryUrl),
|
||||
// azureHeadersPagedCustom(
|
||||
// token.access_token,
|
||||
// showNumberOfRecords
|
||||
// )
|
||||
// )
|
||||
// .then(async ({ data }) => {
|
||||
// var dataStr;
|
||||
// _.has(data, "@odata.nextLink") == true &&
|
||||
// ((dataStr = JSON.stringify(data["@odata.nextLink"])),
|
||||
// (data["@odata.nextLink"] = dataStr.split("/v8.2/")[1]));
|
||||
|
||||
// if (_.has(searchString, "projecttype")) {
|
||||
// await updateValueArray(data, token);
|
||||
|
||||
// async function updateValueArray(data, token) {
|
||||
// let hasNextPage = true;
|
||||
// let nextPageUrl = data["@odata.nextLink"];
|
||||
|
||||
// // Loop through all pages
|
||||
// while (hasNextPage) {
|
||||
// // Iterate through current data and process it
|
||||
// for (let i = 0; i < data.value.length; i++) {
|
||||
// const item = data.value[i];
|
||||
|
||||
// try {
|
||||
// // Axios call using the `incidentid` to fetch additional data
|
||||
// const response = await axios.get(
|
||||
// WEBAPI_URL +
|
||||
// "pinswg_sipses?$filter=_pinswg_sipscase_value eq " +
|
||||
// item.incidentid +
|
||||
// " and _pinswg_projecttype_value eq " +
|
||||
// searchString.projecttype +
|
||||
// "&$select=_pinswg_projecttype_value" +
|
||||
// hashAPIPath(
|
||||
// "pinswg_sipses?$filter=_pinswg_sipscase_value eq " +
|
||||
// item.incidentid +
|
||||
// " and _pinswg_projecttype_value eq " +
|
||||
// searchString.projecttype +
|
||||
// "&$select=_pinswg_projecttype_value"
|
||||
// ),
|
||||
// azureHeadersPaged(token.access_token)
|
||||
// );
|
||||
|
||||
// if (
|
||||
// response.data.value.length > 0 &&
|
||||
// response.data.value[0]
|
||||
// ._pinswg_projecttype_value != null
|
||||
// ) {
|
||||
// Object.assign(
|
||||
// item,
|
||||
// response.data.value[0]
|
||||
// ); // Update item with new data
|
||||
// } else {
|
||||
// console.log(
|
||||
// `No project type found for incident ID ${item.incidentid}`
|
||||
// );
|
||||
// }
|
||||
// } catch (error) {
|
||||
// console.error(
|
||||
// `Error fetching data for incident ID ${item.incidentid}:`,
|
||||
// error
|
||||
// );
|
||||
// }
|
||||
// }
|
||||
|
||||
// // If there's a next page, fetch it
|
||||
// if (nextPageUrl) {
|
||||
// const nextPageData = await axios.get(
|
||||
// WEBAPI_URL +
|
||||
// nextPageUrl +
|
||||
// hashAPIPath(nextPageUrl),
|
||||
// azureHeadersPaged(token.access_token)
|
||||
// );
|
||||
// data.value = [
|
||||
// ...data.value,
|
||||
// ...nextPageData.data.value,
|
||||
// ];
|
||||
// nextPageUrl =
|
||||
// nextPageData.data["@odata.nextLink"];
|
||||
// } else {
|
||||
// hasNextPage = false;
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
// data.value = data.value.filter(
|
||||
// (item) => item._pinswg_projecttype_value != null
|
||||
// );
|
||||
|
||||
// data["@odata.count"] = data.value.length;
|
||||
// }
|
||||
|
||||
// res.status(200).json(data);
|
||||
// })
|
||||
// .catch((error) => {
|
||||
// consoleLogger(error);
|
||||
// res.status(400).json(error);
|
||||
// });
|
||||
|
||||
// return apiResponse;
|
||||
// }
|
||||
|
||||
Reference in New Issue
Block a user