refactor(api): migrate batch 6 endpoints to relayGet

This commit is contained in:
2026-03-24 09:28:01 +00:00
parent 5797443edc
commit 6da6fdb4d2
8 changed files with 144 additions and 139 deletions
+12 -28
View File
@@ -1,13 +1,5 @@
import axios from "axios";
import { azureHeaders } from "../../../actions/core/headers";
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/";
import { respondError } from "../middleware/apiResponse";
import { relayGet } from "../middleware/relayForwarding";
export default async function ApiProxy(req, res) {
const whichForm = req.query.whichForm;
@@ -20,26 +12,18 @@ export default async function ApiProxy(req, res) {
});
}
try {
const token = await getToken();
const queryUrl =
"systemforms?$select=formid,name,formxml,type,objecttypecode&$filter=(objecttypecode eq 'pinswg_" +
whichForm +
"' and type eq 2)&$count=true&$top=201";
const queryUrl =
"systemforms?$select=formid,name,formxml,type,objecttypecode&$filter=(objecttypecode eq 'pinswg_" +
whichForm +
"' and type eq 2)&$count=true&$top=201";
const { data } = await axios.get(
WEBAPI_URL + queryUrl + hashAPIPath(queryUrl),
azureHeaders(token.access_token)
);
return respondSuccess(res, data);
} catch (error) {
consoleLogger(error);
return respondError(res, {
return relayGet({
queryUrl,
res,
errorResponse: {
status: 400,
code: "FORM_DATA_FETCH_FAILED",
message: "Failed to fetch form data"
});
}
}
});
}