/** * @swagger * /api/endpoint/getbasicdnssearchpaged_api: * get: * tags: [Search] * description: Basic DNS search paged * parameters: * - name: searchString * in: query * required: true * example: farm * schema: * type: string * - name: pageNumber * in: query * required: true * example: 1 * schema: * type: string * - name: orderby * in: query * required: true * example: createdon * schema: * type: string * - name: fieldSort * in: query * required: true * description: asc or desc * example: asc * schema: * type: string * - name: showNumberOfRecords * in: query * required: true * description: number of records to return per page * example: 10 * schema: * type: string * responses: * 200: * description: Success */ import axios from "axios"; import _ from "lodash"; import { azureHeadersPagedCustom } from "../../../actions/core/headers"; import { getToken } from "../../../actions/core/token"; import { consoleLogger } from "../../../actions/core/logger"; 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 pageNumber = req.query.pageNumber; const orderby = req.query.orderby; const fieldSort = req.query.fieldSort; const showNumberOfRecords = req.query.showNumberOfRecords; if (typeof orderby !== "string" || orderby.trim().length === 0) { return respondError(res, { status: 400, code: "ORDER_BY_REQUIRED", message: "orderby is required" }); } if (typeof fieldSort !== "string" || fieldSort.trim().length === 0) { return respondError(res, { status: 400, code: "FIELD_SORT_REQUIRED", message: "fieldSort is required" }); } if ( typeof showNumberOfRecords !== "string" || showNumberOfRecords.trim().length === 0 ) { return respondError(res, { status: 400, code: "SHOW_NUMBER_OF_RECORDS_REQUIRED", message: "showNumberOfRecords is required" }); } try { const token = await getToken(); 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&$expand=primarycontactid($select=fullname)&$filter=(pinswg_appealcasetype eq 846040011 or pinswg_appealcasetype eq 846040002) and pinswg_publishtoweb eq true&$orderby=" + orderby + " " + fieldSort + "&$count=true" + (typeof pageNumber != "undefined" ? "&$skiptoken=" + '' : ""); const { data } = await axios.get( WEBAPI_URL + queryUrl + hashAPIPath(queryUrl), azureHeadersPagedCustom(token.access_token, showNumberOfRecords) ); 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, code: "BASIC_DNS_SEARCH_PAGED_FETCH_FAILED", message: "Failed to fetch paged basic DNS search results" }); } }