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

59 lines
1.9 KiB
JavaScript

/**
* @swagger
* /api/endpoint/getmycases_api:
* get:
* tags: [Portal]
* description: Get My Cases
* summary: Phase 2
* parameters:
* - name: loggedInUserId
* in: query
* required: true
* example: 726158c6-708d-ec11-aad8-00224800be9c
* schema:
* type: string
* responses:
* 200:
* description: Success
*/
import { respondError } from "../middleware/apiResponse";
import { relayGet } from "../middleware/relayForwarding";
export default async function ApiProxy(req, res) {
const loggedInUserId = req.query.loggedInUserId;
if (
typeof loggedInUserId !== "string" ||
loggedInUserId.trim().length === 0
) {
return respondError(res, {
status: 400,
code: "LOGGED_IN_USER_ID_REQUIRED",
message: "loggedInUserId is required"
});
}
const queryUrl =
"incidents?$select=pinswg_environmentalstatementlocation,modifiedon,pinswg_publishtoweb,description,numberofchildincidents,_accountid_value,_customerid_value,_pinswg_associatedlpa_value,_ownerid_value,pinswg_appealcasetype,statuscode,ticketnumber,title, _primarycontactid_value,pinswg_lpareference,pinswg_appellantlastname,pinswg_appellantfirstname,pinswg_appellantagent,pinswg_agentfirstname,pinswg_agentlastname,pinswg_agentcompanyname&$expand=primarycontactid($select=fullname)&$filter=_customerid_value eq " +
loggedInUserId +
" and pinswg_appealcasetype ne null&$orderby=createdon desc&$count=true";
return relayGet({
queryUrl,
res,
transformData: (data) => {
data.value.forEach(function (element) {
element.pinswg_title = element.title;
});
return data;
},
errorResponse: {
status: 400,
code: "MY_CASES_FETCH_FAILED",
message: "Failed to fetch my cases"
}
});
}