refactor(api): migrate batch 12 remaining relay-get candidates

This commit is contained in:
2026-03-24 10:27:27 +00:00
parent bf1ba9bc1e
commit da29e789c0
9 changed files with 194 additions and 172 deletions
+18 -10
View File
@@ -15,26 +15,30 @@ import { consoleLogger } from "../../../actions/core/logger";
import { getToken } from "../../../actions/core/token";
import { hashAPIPath } from "../../../actions/core/hash";
import { respondError, respondSuccess } from "../middleware/apiResponse";
import { relayGetData } from "../middleware/relayForwarding";
const WEBAPI_URL =
process.env.RELAY_ROOT ||
"https://dev-pedw-ns.servicebus.windows.net/dev-pedw-hc/";
const recordExists = async (incidentId, contactId, token) => {
const recordExists = async (incidentId, contactId, accessToken) => {
const filter = `$filter=pinswg_WatchedCase/incidentid eq ${incidentId} and pinswg_Contact/contactid eq ${contactId}`;
const queryUrl = `pinswg_watchlists?${filter}`;
const url = WEBAPI_URL + queryUrl + hashAPIPath(queryUrl);
try {
const res = await axios.get(url, {
headers: {
Authorization: "Bearer " + token.access_token,
Accept: "application/json"
}
const response = await relayGetData({
queryUrl,
accessToken,
requestOptionsBuilder: (token) => ({
headers: {
Authorization: "Bearer " + token,
Accept: "application/json"
}
})
});
if (res.data.value && res.data.value.length > 0) {
return res.data.value[0]; // return the existing record
if (response.data.value && response.data.value.length > 0) {
return response.data.value[0]; // return the existing record
}
return null;
@@ -79,7 +83,11 @@ export default async function ApiProxy(req, res) {
const incidentId = watchedCaseMatch[1];
const contactId = contactMatch[1];
const existingRecord = await recordExists(incidentId, contactId, token);
const existingRecord = await recordExists(
incidentId,
contactId,
token.access_token
);
let method, queryUrl;