82 lines
2.5 KiB
JavaScript
82 lines
2.5 KiB
JavaScript
/**
|
|
* @swagger
|
|
* /api/endpoint/updatecase_api:
|
|
* patch:
|
|
* tags: [Case]
|
|
* description: Update case
|
|
* summary: Phase 2
|
|
* 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 updatePayload = req.body;
|
|
const appealObj = req.query.appealObj;
|
|
const updateFormCollection = req.query.updateFormCollection;
|
|
|
|
if (!updatePayload || typeof updatePayload !== "object") {
|
|
return respondError(res, {
|
|
status: 400,
|
|
code: "CASE_UPDATE_PAYLOAD_REQUIRED",
|
|
message: "Case update payload is required"
|
|
});
|
|
}
|
|
if (typeof appealObj !== "string" || appealObj.trim().length === 0) {
|
|
return respondError(res, {
|
|
status: 400,
|
|
code: "APPEAL_OBJECT_ID_REQUIRED",
|
|
message: "appealObj is required"
|
|
});
|
|
}
|
|
if (
|
|
typeof updateFormCollection !== "string" ||
|
|
updateFormCollection.trim().length === 0
|
|
) {
|
|
return respondError(res, {
|
|
status: 400,
|
|
code: "UPDATE_FORM_COLLECTION_REQUIRED",
|
|
message: "updateFormCollection is required"
|
|
});
|
|
}
|
|
|
|
try {
|
|
const queryUrl = updateFormCollection + "(" + appealObj + ")";
|
|
const token = await getToken();
|
|
|
|
const config = {
|
|
method: "patch",
|
|
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"
|
|
},
|
|
data: JSON.stringify(updatePayload)
|
|
};
|
|
|
|
const { data } = await axios(config);
|
|
return respondSuccess(res, data);
|
|
} catch (error) {
|
|
consoleLogger(error);
|
|
return respondError(res, {
|
|
status: 400,
|
|
code: "CASE_UPDATE_FAILED",
|
|
message: "Failed to update case"
|
|
});
|
|
}
|
|
}
|