refactor(api): migrate batch 4 endpoints to relayGet
This commit is contained in:
@@ -16,42 +16,31 @@
|
|||||||
* description: Success
|
* description: Success
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import axios from "axios";
|
|
||||||
import _ from "lodash";
|
import _ from "lodash";
|
||||||
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) {
|
||||||
try {
|
const queryUrl =
|
||||||
const token = await getToken();
|
"incidents?$select=pinswg_environmentalstatementlocation,pinswg_caseaddress,modifiedon,description,numberofchildincidents,_accountid_value,_customerid_value,_pinswg_associatedlpa_value,_ownerid_value,pinswg_appealcasetype,statuscode,ticketnumber,title, _primarycontactid_value,pinswg_lpareference&$expand=primarycontactid($select=fullname)&$filter=(pinswg_appealcasetype eq 846040011 or pinswg_appealcasetype eq 846040002)and pinswg_publishtoweb eq true&$orderby=createdon desc&$count=true";
|
||||||
|
|
||||||
const queryUrl =
|
return relayGet({
|
||||||
"incidents?$select=pinswg_environmentalstatementlocation,pinswg_caseaddress,modifiedon,description,numberofchildincidents,_accountid_value,_customerid_value,_pinswg_associatedlpa_value,_ownerid_value,pinswg_appealcasetype,statuscode,ticketnumber,title, _primarycontactid_value,pinswg_lpareference&$expand=primarycontactid($select=fullname)&$filter=(pinswg_appealcasetype eq 846040011 or pinswg_appealcasetype eq 846040002)and pinswg_publishtoweb eq true&$orderby=createdon desc&$count=true";
|
queryUrl,
|
||||||
|
res,
|
||||||
|
requestOptionsBuilder: (accessToken) => azureHeadersPaged(accessToken),
|
||||||
|
transformData: (data) => {
|
||||||
|
if (_.has(data, "@odata.nextLink") === true) {
|
||||||
|
const dataStr = JSON.stringify(data["@odata.nextLink"]);
|
||||||
|
data["@odata.nextLink"] = dataStr.split("/v8.2/")[1];
|
||||||
|
}
|
||||||
|
|
||||||
const { data } = await axios.get(
|
return data;
|
||||||
WEBAPI_URL + queryUrl + hashAPIPath(queryUrl),
|
},
|
||||||
azureHeadersPaged(token.access_token)
|
errorResponse: {
|
||||||
);
|
|
||||||
|
|
||||||
if (_.has(data, "@odata.nextLink") === true) {
|
|
||||||
const dataStr = JSON.stringify(data["@odata.nextLink"]);
|
|
||||||
data["@odata.nextLink"] = dataStr.split("/v8.2/")[1];
|
|
||||||
}
|
|
||||||
|
|
||||||
return respondSuccess(res, data);
|
|
||||||
} catch (error) {
|
|
||||||
consoleLogger(error);
|
|
||||||
return respondError(res, {
|
|
||||||
status: 400,
|
status: 400,
|
||||||
code: "BASIC_DNS_SEARCH_FETCH_FAILED",
|
code: "BASIC_DNS_SEARCH_FETCH_FAILED",
|
||||||
message: "Failed to fetch basic DNS search results"
|
message: "Failed to fetch basic DNS search results"
|
||||||
});
|
}
|
||||||
}
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,17 +16,10 @@
|
|||||||
* description: Success
|
* description: Success
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import axios from "axios";
|
|
||||||
import _ from "lodash";
|
import _ from "lodash";
|
||||||
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 searchString = req.query.searchString;
|
const searchString = req.query.searchString;
|
||||||
@@ -39,34 +32,31 @@ export default async function ApiProxy(req, res) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
const escapedSearchString = searchString.replace(/\'/g, "''");
|
||||||
const token = await getToken();
|
|
||||||
const escapedSearchString = searchString.replace(/\'/g, "''");
|
|
||||||
|
|
||||||
const queryUrl =
|
const queryUrl =
|
||||||
"incidents?$select=pinswg_environmentalstatementlocation,modifiedon,description,numberofchildincidents,_accountid_value,_customerid_value,_pinswg_associatedlpa_value,_ownerid_value,pinswg_appealcasetype,statuscode,ticketnumber,title, _primarycontactid_value,pinswg_lpareference&$expand=primarycontactid($select=fullname)&$filter=(contains(title, '" +
|
"incidents?$select=pinswg_environmentalstatementlocation,modifiedon,description,numberofchildincidents,_accountid_value,_customerid_value,_pinswg_associatedlpa_value,_ownerid_value,pinswg_appealcasetype,statuscode,ticketnumber,title, _primarycontactid_value,pinswg_lpareference&$expand=primarycontactid($select=fullname)&$filter=(contains(title, '" +
|
||||||
escapedSearchString +
|
escapedSearchString +
|
||||||
"') or contains(ticketnumber, '" +
|
"') or contains(ticketnumber, '" +
|
||||||
escapedSearchString +
|
escapedSearchString +
|
||||||
"')) and (pinswg_appealcasetype eq 846040011 or pinswg_appealcasetype eq 846040002 ) and pinswg_publishtoweb eq true&$orderby=createdon desc&$count=true";
|
"')) and (pinswg_appealcasetype eq 846040011 or pinswg_appealcasetype eq 846040002 ) and pinswg_publishtoweb eq true&$orderby=createdon desc&$count=true";
|
||||||
|
|
||||||
const { data } = await axios.get(
|
return relayGet({
|
||||||
WEBAPI_URL + queryUrl + hashAPIPath(queryUrl),
|
queryUrl,
|
||||||
azureHeadersPaged(token.access_token)
|
res,
|
||||||
);
|
requestOptionsBuilder: (accessToken) => azureHeadersPaged(accessToken),
|
||||||
|
transformData: (data) => {
|
||||||
|
let dataStr;
|
||||||
|
_.has(data, "@odata.nextLink") === true &&
|
||||||
|
((dataStr = JSON.stringify(data["@odata.nextLink"])),
|
||||||
|
(data["@odata.nextLink"] = dataStr.split("/v8.2/")[1]));
|
||||||
|
|
||||||
let dataStr;
|
return data;
|
||||||
_.has(data, "@odata.nextLink") === true &&
|
},
|
||||||
((dataStr = JSON.stringify(data["@odata.nextLink"])),
|
errorResponse: {
|
||||||
(data["@odata.nextLink"] = dataStr.split("/v8.2/")[1]));
|
|
||||||
|
|
||||||
return respondSuccess(res, data);
|
|
||||||
} catch (error) {
|
|
||||||
consoleLogger(error);
|
|
||||||
return respondError(res, {
|
|
||||||
status: 400,
|
status: 400,
|
||||||
code: "BASIC_DNS_URL_SEARCH_FETCH_FAILED",
|
code: "BASIC_DNS_URL_SEARCH_FETCH_FAILED",
|
||||||
message: "Failed to fetch DNS URL search results"
|
message: "Failed to fetch DNS URL search results"
|
||||||
});
|
}
|
||||||
}
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,16 +15,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 searchString = req.query.searchString;
|
const searchString = req.query.searchString;
|
||||||
@@ -37,40 +30,37 @@ export default async function ApiProxy(req, res) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
const escapedSearchString = searchString.replace(/\'/g, "''");
|
||||||
const token = await getToken();
|
|
||||||
const escapedSearchString = searchString.replace(/\'/g, "''");
|
|
||||||
|
|
||||||
const queryUrl =
|
const queryUrl =
|
||||||
"incidents?$select=pinswg_environmentalstatementlocation,pinswg_caseaddress,modifiedon,description,numberofchildincidents,_accountid_value,_customerid_value,_pinswg_associatedlpa_value,_ownerid_value,pinswg_appealcasetype,statuscode,ticketnumber,title, _primarycontactid_value,pinswg_lpareference,pinswg_appellantagent,pinswg_appellantfirstname,pinswg_appellantlastname&$expand=primarycontactid($select=fullname)&$filter=(contains(title, '" +
|
"incidents?$select=pinswg_environmentalstatementlocation,pinswg_caseaddress,modifiedon,description,numberofchildincidents,_accountid_value,_customerid_value,_pinswg_associatedlpa_value,_ownerid_value,pinswg_appealcasetype,statuscode,ticketnumber,title, _primarycontactid_value,pinswg_lpareference,pinswg_appellantagent,pinswg_appellantfirstname,pinswg_appellantlastname&$expand=primarycontactid($select=fullname)&$filter=(contains(title, '" +
|
||||||
escapedSearchString +
|
escapedSearchString +
|
||||||
"') or contains(ticketnumber, '" +
|
"') or contains(ticketnumber, '" +
|
||||||
escapedSearchString +
|
escapedSearchString +
|
||||||
"') or contains(pinswg_lpareference, '" +
|
"') or contains(pinswg_lpareference, '" +
|
||||||
escapedSearchString +
|
escapedSearchString +
|
||||||
"')) and pinswg_appealcasetype ne null " +
|
"')) and pinswg_appealcasetype ne null " +
|
||||||
(process.env.SHOWSIPS !== "true"
|
(process.env.SHOWSIPS !== "true"
|
||||||
? "and pinswg_appealcasetype ne 846040002 "
|
? "and pinswg_appealcasetype ne 846040002 "
|
||||||
: "") +
|
: "") +
|
||||||
"and pinswg_publishtoweb eq true&$orderby=createdon desc&$count=true";
|
"and pinswg_publishtoweb eq true&$orderby=createdon desc&$count=true";
|
||||||
|
|
||||||
const { data } = await axios.get(
|
return relayGet({
|
||||||
WEBAPI_URL + queryUrl + hashAPIPath(queryUrl),
|
queryUrl,
|
||||||
azureHeadersPaged(token.access_token)
|
res,
|
||||||
);
|
requestOptionsBuilder: (accessToken) => azureHeadersPaged(accessToken),
|
||||||
|
transformData: (data) => {
|
||||||
|
if (Object.prototype.hasOwnProperty.call(data, "@odata.nextLink")) {
|
||||||
|
const dataStr = JSON.stringify(data["@odata.nextLink"]);
|
||||||
|
data["@odata.nextLink"] = dataStr.split("/v8.2/")[1];
|
||||||
|
}
|
||||||
|
|
||||||
if (Object.prototype.hasOwnProperty.call(data, "@odata.nextLink")) {
|
return data;
|
||||||
const dataStr = JSON.stringify(data["@odata.nextLink"]);
|
},
|
||||||
data["@odata.nextLink"] = dataStr.split("/v8.2/")[1];
|
errorResponse: {
|
||||||
}
|
|
||||||
|
|
||||||
return respondSuccess(res, data);
|
|
||||||
} catch (error) {
|
|
||||||
consoleLogger(error);
|
|
||||||
return respondError(res, {
|
|
||||||
status: 400,
|
status: 400,
|
||||||
code: "BASIC_SEARCH_FETCH_FAILED",
|
code: "BASIC_SEARCH_FETCH_FAILED",
|
||||||
message: "Failed to fetch basic search results"
|
message: "Failed to fetch basic search results"
|
||||||
});
|
}
|
||||||
}
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,16 +15,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 caseId = req.query.id;
|
const caseId = req.query.id;
|
||||||
@@ -37,26 +30,19 @@ export default async function ApiProxy(req, res) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
const queryUrl =
|
||||||
const token = await getToken();
|
"tasks?$select=_regardingobjectid_value,subject,description,createdon,statuscode,scheduledend,scheduledstart&$count=true&$filter=_regardingobjectid_value eq " +
|
||||||
|
caseId +
|
||||||
|
" and contains(subject, 'Banner') and statuscode ne 5&$orderby=createdon desc";
|
||||||
|
|
||||||
const queryUrl =
|
return relayGet({
|
||||||
"tasks?$select=_regardingobjectid_value,subject,description,createdon,statuscode,scheduledend,scheduledstart&$count=true&$filter=_regardingobjectid_value eq " +
|
queryUrl,
|
||||||
caseId +
|
res,
|
||||||
" and contains(subject, 'Banner') and statuscode ne 5&$orderby=createdon desc";
|
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: "CASE_MESSAGE_FETCH_FAILED",
|
code: "CASE_MESSAGE_FETCH_FAILED",
|
||||||
message: "Failed to fetch case messages"
|
message: "Failed to fetch case messages"
|
||||||
});
|
}
|
||||||
}
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,14 +1,7 @@
|
|||||||
import axios from "axios";
|
|
||||||
import _ from "lodash";
|
import _ from "lodash";
|
||||||
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 searchString = req.query.searchString;
|
const searchString = req.query.searchString;
|
||||||
@@ -21,34 +14,31 @@ export default async function ApiProxy(req, res) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
const escapedSearchString = searchString.replace(/\'/g, "''");
|
||||||
const token = await getToken();
|
|
||||||
const escapedSearchString = searchString.replace(/\'/g, "''");
|
|
||||||
|
|
||||||
const queryUrl =
|
const queryUrl =
|
||||||
"incidents?$select=pinswg_environmentalstatementlocation,modifiedon,description,numberofchildincidents,_accountid_value,_customerid_value,_pinswg_associatedlpa_value,_ownerid_value,pinswg_appealcasetype,statuscode,ticketnumber,title, _primarycontactid_value,pinswg_lpareference,pinswg_appellantagent,pinswg_appellantfirstname,pinswg_appellantlastname&$expand=primarycontactid($select=fullname)&$filter=(contains(title, '" +
|
"incidents?$select=pinswg_environmentalstatementlocation,modifiedon,description,numberofchildincidents,_accountid_value,_customerid_value,_pinswg_associatedlpa_value,_ownerid_value,pinswg_appealcasetype,statuscode,ticketnumber,title, _primarycontactid_value,pinswg_lpareference,pinswg_appellantagent,pinswg_appellantfirstname,pinswg_appellantlastname&$expand=primarycontactid($select=fullname)&$filter=(contains(title, '" +
|
||||||
escapedSearchString +
|
escapedSearchString +
|
||||||
"') or contains(ticketnumber, '" +
|
"') or contains(ticketnumber, '" +
|
||||||
escapedSearchString +
|
escapedSearchString +
|
||||||
"')) and pinswg_appealcasetype ne null&$orderby=createdon desc&$count=true";
|
"')) and pinswg_appealcasetype ne null&$orderby=createdon desc&$count=true";
|
||||||
|
|
||||||
const { data } = await axios.get(
|
return relayGet({
|
||||||
WEBAPI_URL + queryUrl + hashAPIPath(queryUrl),
|
queryUrl,
|
||||||
azureHeadersPaged(token.access_token)
|
res,
|
||||||
);
|
requestOptionsBuilder: (accessToken) => azureHeadersPaged(accessToken),
|
||||||
|
transformData: (data) => {
|
||||||
|
let dataStr;
|
||||||
|
_.has(data, "@odata.nextLink") === true &&
|
||||||
|
((dataStr = JSON.stringify(data["@odata.nextLink"])),
|
||||||
|
(data["@odata.nextLink"] = dataStr.split("/v8.2/")[1]));
|
||||||
|
|
||||||
let dataStr;
|
return data;
|
||||||
_.has(data, "@odata.nextLink") === true &&
|
},
|
||||||
((dataStr = JSON.stringify(data["@odata.nextLink"])),
|
errorResponse: {
|
||||||
(data["@odata.nextLink"] = dataStr.split("/v8.2/")[1]));
|
|
||||||
|
|
||||||
return respondSuccess(res, data);
|
|
||||||
} catch (error) {
|
|
||||||
consoleLogger(error);
|
|
||||||
return respondError(res, {
|
|
||||||
status: 400,
|
status: 400,
|
||||||
code: "PART_SAVED_APPEAL_FETCH_FAILED",
|
code: "PART_SAVED_APPEAL_FETCH_FAILED",
|
||||||
message: "Failed to fetch part-saved appeals"
|
message: "Failed to fetch part-saved appeals"
|
||||||
});
|
}
|
||||||
}
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user