88 lines
2.5 KiB
JavaScript
88 lines
2.5 KiB
JavaScript
/**
|
|
* @swagger
|
|
* /api/endpoint/getportalmoduledetailsproxy_api:
|
|
* get:
|
|
* tags: [Portal]
|
|
* description: Get portal module details proxy
|
|
* summary: Phase 2
|
|
* parameters:
|
|
* - name: appealType
|
|
* in: query
|
|
* required: true
|
|
* example: pinswg_planningappeals78s
|
|
* schema:
|
|
* type: string
|
|
* - name: caseReference
|
|
* in: query
|
|
* required: true
|
|
* example: CAS-00764-L0Q9W2
|
|
* schema:
|
|
* type: string
|
|
* responses:
|
|
* 200:
|
|
* description: hello world
|
|
*/
|
|
|
|
import axios from "axios";
|
|
import { azureHeaders } from "../../../actions/core/headers";
|
|
import { consoleLogger } from "../../../actions/core/logger";
|
|
import { getToken } from "../../../actions/core/token";
|
|
import { getSelectQuery } from "../../../actions/selectQueryTypes";
|
|
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) {
|
|
const appealType = req.query.appealType;
|
|
const caseReference = req.query.caseReference;
|
|
|
|
if (typeof appealType !== "string" || appealType.trim().length === 0) {
|
|
return respondError(res, {
|
|
status: 400,
|
|
code: "APPEAL_TYPE_REQUIRED",
|
|
message: "appealType is required"
|
|
});
|
|
}
|
|
|
|
if (
|
|
typeof caseReference !== "string" ||
|
|
caseReference.trim().length === 0
|
|
) {
|
|
return respondError(res, {
|
|
status: 400,
|
|
code: "CASE_REFERENCE_REQUIRED",
|
|
message: "caseReference is required"
|
|
});
|
|
}
|
|
|
|
try {
|
|
const token = await getToken();
|
|
const escapedCaseReference = caseReference.split("'").join("''");
|
|
|
|
let queryUrl =
|
|
appealType +
|
|
"?$filter=pinswg_name eq '" +
|
|
escapedCaseReference +
|
|
"'&$count=true";
|
|
|
|
queryUrl = queryUrl + getSelectQuery(appealType);
|
|
|
|
const { data } = await axios.get(
|
|
WEBAPI_URL + queryUrl + hashAPIPath(queryUrl),
|
|
azureHeaders(token.access_token)
|
|
);
|
|
|
|
return respondSuccess(res, data);
|
|
} catch (error) {
|
|
consoleLogger(error);
|
|
return respondError(res, {
|
|
status: 400,
|
|
code: "PORTAL_MODULE_DETAILS_PROXY_FETCH_FAILED",
|
|
message: "Failed to fetch portal module details proxy"
|
|
});
|
|
}
|
|
}
|