TASK22211: normalize basic search endpoint contracts
This commit is contained in:
@@ -1,9 +1,9 @@
|
||||
import axios from "axios";
|
||||
import CryptoJS from "crypto-js";
|
||||
import { azureHeaders } from "../../../actions/core/headers";
|
||||
import { consoleLogger } from "../../../actions/core/logger";
|
||||
import { getToken } from "../../../actions/core/token";
|
||||
import { hashAPIPath } from "../../../actions/core/hash";
|
||||
import { respondError, respondSuccess } from "../middleware/apiResponse";
|
||||
|
||||
const WEBAPI_URL =
|
||||
process.env.RELAY_ROOT ||
|
||||
@@ -285,9 +285,11 @@ export default async function ApiProxy(req, res) {
|
||||
let lpaRef = (req.query.lpaRef || "").trim();
|
||||
|
||||
if (!lpaRef) {
|
||||
return res
|
||||
.status(400)
|
||||
.json({ error: "Missing required query param: lpaRef" });
|
||||
return respondError(res, {
|
||||
status: 400,
|
||||
code: "LPA_REF_REQUIRED",
|
||||
message: "lpaRef is required"
|
||||
});
|
||||
}
|
||||
|
||||
// ✅ Escape single quotes for OData
|
||||
@@ -298,10 +300,6 @@ export default async function ApiProxy(req, res) {
|
||||
// contains(tolower(pinswg_lpaapplicationreference), 'lowered search')
|
||||
const lowered = lpaRef.toLowerCase();
|
||||
|
||||
console.log(
|
||||
`\n=== LPA REF SEARCH ===\nSearching for "${lpaRef}" (case-insensitive contains)\nAcross ${appealTypeArrayWithLpaRef.length} entity types\n======================\n`
|
||||
);
|
||||
|
||||
const resultsPerType = await Promise.all(
|
||||
appealTypeArrayWithLpaRef.map(async (item) => {
|
||||
// You can expand/select more fields if needed, but keep light for speed
|
||||
@@ -323,17 +321,6 @@ export default async function ApiProxy(req, res) {
|
||||
`&$count=true` +
|
||||
`&$orderby=modifiedon desc`;
|
||||
|
||||
console.log(
|
||||
"\n------------------------------------------\n",
|
||||
"Entity:",
|
||||
item.LogicalCollectionName,
|
||||
"\nQuery:",
|
||||
queryUrl,
|
||||
"\nFull:",
|
||||
WEBAPI_URL + queryUrl + hashAPIPath(queryUrl),
|
||||
"\n------------------------------------------\n"
|
||||
);
|
||||
|
||||
const { data } = await axios.get(
|
||||
WEBAPI_URL + queryUrl + hashAPIPath(queryUrl),
|
||||
azureHeaders(token.access_token)
|
||||
@@ -353,10 +340,6 @@ export default async function ApiProxy(req, res) {
|
||||
] || null
|
||||
}));
|
||||
|
||||
console.log(
|
||||
`Returned ${normalized.length} records from ${item.LogicalCollectionName}`
|
||||
);
|
||||
|
||||
return normalized;
|
||||
})
|
||||
);
|
||||
@@ -372,9 +355,13 @@ export default async function ApiProxy(req, res) {
|
||||
value: flattened
|
||||
};
|
||||
|
||||
return res.status(200).json(output);
|
||||
return respondSuccess(res, output);
|
||||
} catch (error) {
|
||||
consoleLogger(error);
|
||||
return res.status(400).json(error);
|
||||
return respondError(res, {
|
||||
status: 400,
|
||||
code: "BASIC_SEARCH_LPA_REF_FETCH_FAILED",
|
||||
message: "Failed to fetch basic search by lpa reference"
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user