Files
pedwfrontend/pages/api/endpoint/getappealid_api.js
T

94 lines
2.5 KiB
JavaScript

/**
* @swagger
* /api/endpoint/getappealid_api:
* get:
* tags: [Misc]
* description: Get Appeal ID from
* parameters:
* - name: caseReference
* in: query
* required: true
* example: CAS-00764-L0Q9W2
* schema:
* type: string
* - name: updateFormCollection
* in: query
* required: true
* example: pinswg_planningappeals78s
* schema:
* type: string
* - name: primaryAttribute
* in: query
* required: true
* example: pinswg_planningappeals78id
* schema:
* type: string
* responses:
* 200:
* description: Success
*/
import { azureHeaders } from "../../../actions/core/headers";
import { respondError } from "../middleware/apiResponse";
import { relayGet } from "../middleware/relayForwarding";
export default async function ApiProxy(req, res) {
const caseReference = req.query.caseReference;
const updateFormCollection = req.query.updateFormCollection;
const primaryAttribute = req.query.primaryAttribute;
if (
typeof caseReference !== "string" ||
caseReference.trim().length === 0
) {
return respondError(res, {
status: 400,
code: "CASE_REFERENCE_REQUIRED",
message: "caseReference is required"
});
}
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"
});
}
const escapedCaseReference = caseReference.split("'").join("''");
const queryUrl =
updateFormCollection +
"?$count=true&$select=_" +
primaryAttribute +
"s_value&$filter=pinswg_name eq '" +
escapedCaseReference +
"'";
return relayGet({
queryUrl,
res,
requestOptionsBuilder: (accessToken) => azureHeaders(accessToken),
errorResponse: {
status: 400,
code: "APPEAL_ID_FETCH_FAILED",
message: "Failed to fetch appeal id"
}
});
}