/** * @swagger * /api/endpoint/deleteamywatchedcases_api: * delete: * tags: [Portal,Case] * summary: Phase 2 * description: Delete my watched cases * responses: * 200: * description: Success */ import axios from "axios"; 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) { const watchedCaseID = req.query.watchedCaseID; if ( typeof watchedCaseID !== "string" || watchedCaseID.trim().length === 0 ) { return respondError(res, { status: 400, code: "WATCHED_CASE_ID_REQUIRED", message: "watchedCaseID is required" }); } try { const token = await getToken(); const queryUrl = "pinswg_watchlists(" + watchedCaseID + ")"; const config = { method: "delete", url: WEBAPI_URL + queryUrl + hashAPIPath(queryUrl), headers: { "OData-MaxVersion": "4.0", "OData-Version": "4.0", Accept: "application/json", Prefer: 'odata.include-annotations="*",return=representation', Authorization: "Bearer " + token.access_token, "Content-Type": "application/json" } }; const { data } = await axios(config); return respondSuccess(res, data); } catch (error) { consoleLogger(error); return respondError(res, { status: 400, code: "WATCHED_CASE_DELETE_FAILED", message: "Failed to delete watched case" }); } }