TASK22211: normalize metadata and linked-case endpoint contracts
This commit is contained in:
@@ -29,40 +29,78 @@
|
||||
*/
|
||||
|
||||
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 ||
|
||||
"https://dev-pedw-ns.servicebus.windows.net/dev-pedw-hc/";
|
||||
|
||||
export default async function ApiProxy(req, res) {
|
||||
var caseReference = req.query.caseReference;
|
||||
var updateFormCollection = req.query.updateFormCollection;
|
||||
var primaryAttribute = req.query.primaryAttribute;
|
||||
var token = await getToken();
|
||||
const caseReference = req.query.caseReference;
|
||||
const updateFormCollection = req.query.updateFormCollection;
|
||||
const primaryAttribute = req.query.primaryAttribute;
|
||||
|
||||
const queryUrl =
|
||||
updateFormCollection +
|
||||
"?$count=true&$select=_" +
|
||||
primaryAttribute +
|
||||
"s_value&$filter=pinswg_name eq '" +
|
||||
caseReference +
|
||||
"'";
|
||||
if (
|
||||
typeof caseReference !== "string" ||
|
||||
caseReference.trim().length === 0
|
||||
) {
|
||||
return respondError(res, {
|
||||
status: 400,
|
||||
code: "CASE_REFERENCE_REQUIRED",
|
||||
message: "caseReference is required"
|
||||
});
|
||||
}
|
||||
|
||||
return axios
|
||||
.get(
|
||||
if (
|
||||
typeof updateFormCollection !== "string" ||
|
||||
updateFormCollection.trim().length === 0
|
||||
) {
|
||||
return respondError(res, {
|
||||
status: 400,
|
||||
code: "UPDATE_FORM_COLLECTION_REQUIRED",
|
||||
message: "updateFormCollection is required"
|
||||
});
|
||||
}
|
||||
|
||||
if (
|
||||
typeof primaryAttribute !== "string" ||
|
||||
primaryAttribute.trim().length === 0
|
||||
) {
|
||||
return respondError(res, {
|
||||
status: 400,
|
||||
code: "PRIMARY_ATTRIBUTE_REQUIRED",
|
||||
message: "primaryAttribute is required"
|
||||
});
|
||||
}
|
||||
|
||||
try {
|
||||
const token = await getToken();
|
||||
const escapedCaseReference = caseReference.split("'").join("''");
|
||||
|
||||
const queryUrl =
|
||||
updateFormCollection +
|
||||
"?$count=true&$select=_" +
|
||||
primaryAttribute +
|
||||
"s_value&$filter=pinswg_name eq '" +
|
||||
escapedCaseReference +
|
||||
"'";
|
||||
|
||||
const { data } = await axios.get(
|
||||
WEBAPI_URL + queryUrl + hashAPIPath(queryUrl),
|
||||
azureHeaders(token.access_token)
|
||||
)
|
||||
.then(({ data }) => {
|
||||
res.status(200).json(data);
|
||||
})
|
||||
.catch((error) => {
|
||||
consoleLogger(error);
|
||||
res.status(400).json(error);
|
||||
);
|
||||
|
||||
return respondSuccess(res, data);
|
||||
} catch (error) {
|
||||
consoleLogger(error);
|
||||
return respondError(res, {
|
||||
status: 400,
|
||||
code: "APPEAL_ID_FETCH_FAILED",
|
||||
message: "Failed to fetch appeal id"
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user