refactor(api): migrate batch 5 endpoints to relayGet
This commit is contained in:
@@ -9,46 +9,30 @@
|
|||||||
* description: Success
|
* description: Success
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import axios from "axios";
|
import { respondError } from "../middleware/apiResponse";
|
||||||
import { azureHeaders } from "../../../actions/core/headers";
|
import { relayGet } from "../middleware/relayForwarding";
|
||||||
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) {
|
export default async function ApiProxy(req, res) {
|
||||||
try {
|
const queryUrl =
|
||||||
const token = await getToken();
|
"stringmaps?$filter=objecttypecode eq 'incident' and attributename eq 'pinswg_appealcasetype' " +
|
||||||
|
(process.env.SHOWSIPS !== "true"
|
||||||
|
? "and attributevalue ne 846040002"
|
||||||
|
: "") +
|
||||||
|
"&$count=true&$select=value,stringmapid,organizationid,attributevalue&$orderby=value asc";
|
||||||
|
|
||||||
const queryUrl =
|
// for sips
|
||||||
"stringmaps?$filter=objecttypecode eq 'incident' and attributename eq 'pinswg_appealcasetype' " +
|
// "stringmaps?$filter=objecttypecode eq 'incident' and attributename eq 'pinswg_appealcasetype'&$count=true&$select=value,stringmapid,organizationid,attributevalue&$orderby=value asc";
|
||||||
(process.env.SHOWSIPS !== "true"
|
|
||||||
? "and attributevalue ne 846040002"
|
|
||||||
: "") +
|
|
||||||
"&$count=true&$select=value,stringmapid,organizationid,attributevalue&$orderby=value asc";
|
|
||||||
|
|
||||||
// for sips
|
// "stringmaps?$filter=objecttypecode eq 'incident' and attributename eq 'pinswg_appealcasetype' and value ne 'Misc Casework'&$count=true&$select=value,stringmapid,organizationid,attributevalue&$orderby=value asc";
|
||||||
// "stringmaps?$filter=objecttypecode eq 'incident' and attributename eq 'pinswg_appealcasetype'&$count=true&$select=value,stringmapid,organizationid,attributevalue&$orderby=value asc";
|
//"stringmaps?$filter=objecttypecode eq 'incident' and attributename eq 'pinswg_appealcasetype' and value ne 'Developments of National Significance' and value ne 'LDP' and value ne 'Misc Casework'&$count=true&$select=value,stringmapid,organizationid,attributevalue&$orderby=value asc";
|
||||||
|
|
||||||
// "stringmaps?$filter=objecttypecode eq 'incident' and attributename eq 'pinswg_appealcasetype' and value ne 'Misc Casework'&$count=true&$select=value,stringmapid,organizationid,attributevalue&$orderby=value asc";
|
return relayGet({
|
||||||
//"stringmaps?$filter=objecttypecode eq 'incident' and attributename eq 'pinswg_appealcasetype' and value ne 'Developments of National Significance' and value ne 'LDP' and value ne 'Misc Casework'&$count=true&$select=value,stringmapid,organizationid,attributevalue&$orderby=value asc";
|
queryUrl,
|
||||||
|
res,
|
||||||
const { data } = await axios.get(
|
errorResponse: {
|
||||||
WEBAPI_URL + queryUrl + hashAPIPath(queryUrl),
|
|
||||||
azureHeaders(token.access_token)
|
|
||||||
);
|
|
||||||
|
|
||||||
return respondSuccess(res, data);
|
|
||||||
} catch (error) {
|
|
||||||
consoleLogger(error);
|
|
||||||
return respondError(res, {
|
|
||||||
status: 400,
|
status: 400,
|
||||||
code: "APPEAL_TYPES_FETCH_FAILED",
|
code: "APPEAL_TYPES_FETCH_FAILED",
|
||||||
message: "Failed to fetch appeal types"
|
message: "Failed to fetch appeal types"
|
||||||
});
|
}
|
||||||
}
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,16 +15,8 @@
|
|||||||
* description: Success
|
* description: Success
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import axios from "axios";
|
import { respondError } from "../middleware/apiResponse";
|
||||||
import { azureHeaders } from "../../../actions/core/headers";
|
import { relayGet } from "../middleware/relayForwarding";
|
||||||
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) {
|
export default async function ApiProxy(req, res) {
|
||||||
const searchString = req.query.searchString;
|
const searchString = req.query.searchString;
|
||||||
@@ -37,28 +29,20 @@ export default async function ApiProxy(req, res) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
const escapedSearchString = searchString.split("'").join("''");
|
||||||
const token = await getToken();
|
|
||||||
|
|
||||||
const escapedSearchString = searchString.split("'").join("''");
|
const queryUrl =
|
||||||
|
"incidents?$select=pinswg_environmentalstatementlocation,pinswg_publishtoweb,ticketnumber,title, _primarycontactid_value&$filter=incidentid eq " +
|
||||||
|
escapedSearchString +
|
||||||
|
" and pinswg_appealcasetype ne null &$orderby=createdon desc&$count=true";
|
||||||
|
|
||||||
const queryUrl =
|
return relayGet({
|
||||||
"incidents?$select=pinswg_environmentalstatementlocation,pinswg_publishtoweb,ticketnumber,title, _primarycontactid_value&$filter=incidentid eq " +
|
queryUrl,
|
||||||
escapedSearchString +
|
res,
|
||||||
" and pinswg_appealcasetype ne null &$orderby=createdon desc&$count=true";
|
errorResponse: {
|
||||||
|
|
||||||
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, {
|
|
||||||
status: 400,
|
status: 400,
|
||||||
code: "IS_PUBLISHED_FETCH_FAILED",
|
code: "IS_PUBLISHED_FETCH_FAILED",
|
||||||
message: "Failed to fetch published state"
|
message: "Failed to fetch published state"
|
||||||
});
|
}
|
||||||
}
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,16 +16,9 @@
|
|||||||
* description: Success
|
* description: Success
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import axios from "axios";
|
|
||||||
import { azureHeadersPaged } from "../../../actions/core/headers";
|
import { azureHeadersPaged } from "../../../actions/core/headers";
|
||||||
import { consoleLogger } from "../../../actions/core/logger";
|
import { respondError } from "../middleware/apiResponse";
|
||||||
import { getToken } from "../../../actions/core/token";
|
import { relayGet } from "../middleware/relayForwarding";
|
||||||
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) {
|
export default async function ApiProxy(req, res) {
|
||||||
const parentIncidentid = req.query.parentincidentid;
|
const parentIncidentid = req.query.parentincidentid;
|
||||||
@@ -41,26 +34,19 @@ export default async function ApiProxy(req, res) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
const queryUrl =
|
||||||
const token = await getToken();
|
"incidents?$count=true&$filter=_parentcaseid_value eq " +
|
||||||
|
parentIncidentid +
|
||||||
|
" and pinswg_appealcasetype ne null and pinswg_publishtoweb eq true &$select=title, incidentid";
|
||||||
|
|
||||||
const queryUrl =
|
return relayGet({
|
||||||
"incidents?$count=true&$filter=_parentcaseid_value eq " +
|
queryUrl,
|
||||||
parentIncidentid +
|
res,
|
||||||
" and pinswg_appealcasetype ne null and pinswg_publishtoweb eq true &$select=title, incidentid";
|
requestOptionsBuilder: (accessToken) => azureHeadersPaged(accessToken),
|
||||||
|
errorResponse: {
|
||||||
const { data } = await axios.get(
|
|
||||||
WEBAPI_URL + queryUrl + hashAPIPath(queryUrl),
|
|
||||||
azureHeadersPaged(token.access_token)
|
|
||||||
);
|
|
||||||
|
|
||||||
return respondSuccess(res, data);
|
|
||||||
} catch (error) {
|
|
||||||
consoleLogger(error);
|
|
||||||
return respondError(res, {
|
|
||||||
status: 400,
|
status: 400,
|
||||||
code: "LINKED_CASES_FETCH_FAILED",
|
code: "LINKED_CASES_FETCH_FAILED",
|
||||||
message: "Failed to fetch linked cases"
|
message: "Failed to fetch linked cases"
|
||||||
});
|
}
|
||||||
}
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,36 +12,20 @@
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import axios from "axios";
|
import { respondError } from "../middleware/apiResponse";
|
||||||
import { azureHeaders } from "../../../actions/core/headers";
|
import { relayGet } from "../middleware/relayForwarding";
|
||||||
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) {
|
export default async function ApiProxy(req, res) {
|
||||||
try {
|
const queryUrl =
|
||||||
const token = await getToken();
|
"accounts?$count=true&$filter=pinswg_isalocalplanningauthorityaccount eq 846040000&$select=name&$orderby=name asc";
|
||||||
|
|
||||||
const queryUrl =
|
return relayGet({
|
||||||
"accounts?$count=true&$filter=pinswg_isalocalplanningauthorityaccount eq 846040000&$select=name&$orderby=name asc";
|
queryUrl,
|
||||||
|
res,
|
||||||
const { data } = await axios.get(
|
errorResponse: {
|
||||||
WEBAPI_URL + queryUrl + hashAPIPath(queryUrl),
|
|
||||||
azureHeaders(token.access_token)
|
|
||||||
);
|
|
||||||
|
|
||||||
return respondSuccess(res, data);
|
|
||||||
} catch (error) {
|
|
||||||
consoleLogger(error);
|
|
||||||
return respondError(res, {
|
|
||||||
status: 400,
|
status: 400,
|
||||||
code: "LPA_FETCH_FAILED",
|
code: "LPA_FETCH_FAILED",
|
||||||
message: "Failed to fetch local planning authorities"
|
message: "Failed to fetch local planning authorities"
|
||||||
});
|
}
|
||||||
}
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,36 +9,20 @@
|
|||||||
* description: Success
|
* description: Success
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import axios from "axios";
|
import { respondError } from "../middleware/apiResponse";
|
||||||
import { azureHeaders } from "../../../actions/core/headers";
|
import { relayGet } from "../middleware/relayForwarding";
|
||||||
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) {
|
export default async function ApiProxy(req, res) {
|
||||||
try {
|
const queryUrl =
|
||||||
const token = await getToken();
|
"pinswg_sipsprojecttypes?$select=pinswg_name,pinswg_sipsprojecttypeid&$orderby=pinswg_name asc&$count=true";
|
||||||
|
|
||||||
const queryUrl =
|
return relayGet({
|
||||||
"pinswg_sipsprojecttypes?$select=pinswg_name,pinswg_sipsprojecttypeid&$orderby=pinswg_name asc&$count=true";
|
queryUrl,
|
||||||
|
res,
|
||||||
const { data } = await axios.get(
|
errorResponse: {
|
||||||
WEBAPI_URL + queryUrl + hashAPIPath(queryUrl),
|
|
||||||
azureHeaders(token.access_token)
|
|
||||||
);
|
|
||||||
|
|
||||||
return respondSuccess(res, data);
|
|
||||||
} catch (error) {
|
|
||||||
consoleLogger(error);
|
|
||||||
return respondError(res, {
|
|
||||||
status: 400,
|
status: 400,
|
||||||
code: "PROJECT_TYPES_FETCH_FAILED",
|
code: "PROJECT_TYPES_FETCH_FAILED",
|
||||||
message: "Failed to fetch project types"
|
message: "Failed to fetch project types"
|
||||||
});
|
}
|
||||||
}
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user