/** * @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 _ from "lodash"; import { azureHeadersPagedCustom } from "../../../actions/core/headers"; import { respondError } from "../middleware/apiResponse"; import { relayGet } from "../middleware/relayForwarding"; 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" }); } 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=" + '' : ""); return relayGet({ queryUrl, res, requestOptionsBuilder: (accessToken) => azureHeadersPagedCustom(accessToken, showNumberOfRecords), transformData: (data) => { if (_.has(data, "@odata.nextLink") === true) { const dataStr = JSON.stringify(data["@odata.nextLink"]); data["@odata.nextLink"] = dataStr.split("/v8.2/")[1]; } return data; }, errorResponse: { status: 400, code: "BASIC_DNS_SEARCH_PAGED_FETCH_FAILED", message: "Failed to fetch paged basic DNS search results" } }); }