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

53 lines
1.4 KiB
JavaScript

/**
* @swagger
* /api/endpoint/getrepresentations_api:
* get:
* tags: [Case]
* description: Get Representations for a Case
* summary: Phase 2
* parameters:
* - name: incidentID
* in: query
* required: true
* example: 50b533aa-43f1-ec11-aade-00224800be9c
* schema:
* type: string
* responses:
* 200:
* description: Success
*/
import { respondError } from "../middleware/apiResponse";
import { relayGet } from "../middleware/relayForwarding";
import { RELAY_POLICY_BOUNDED_READ } from "../middleware/relayPolicyPresets";
export default async function ApiProxy(req, res) {
const incidentID = req.query.incidentID;
if (typeof incidentID !== "string" || incidentID.trim().length === 0) {
return respondError(res, {
status: 400,
code: "INCIDENT_ID_REQUIRED",
message: "incidentID is required"
});
}
const queryUrl =
"pinswg_representationses?$filter= _pinswg_case_value eq " +
incidentID +
" and pinswg_publishtoweb eq true&$count=true&$orderby=createdon desc";
const relayPolicy = RELAY_POLICY_BOUNDED_READ;
return relayGet({
queryUrl,
res,
relayPolicy,
errorResponse: {
status: 400,
code: "REPRESENTATIONS_FETCH_FAILED",
message: "Failed to fetch representations"
}
});
}