@mikezimm/fps-core-v7
Version:
Library of reusable core interfaces, types and constants migrated from fps-library-v2
56 lines • 3.6 kB
JavaScript
import { SourcePropsNoWebUrl } from '../../../components/molecules/source-props/ISourceProps'; ///ISourceProps';
import { check4This, Check4 } from "../../../logic/Links/CheckSearch";
import { doSpHttpFetchOrPostAndCheck } from "../../../components/molecules/SpHttp/Sp/doSpHttpFetch";
import { createErrorFpsListReturn } from '../../../components/molecules/process-results/createErrorFpsListItemsReturn';
import { createSeriesSort } from '../../../components/molecules/source-props/createOrderBy';
import { getExpandColumns } from '../../../components/molecules/source-props/Lists/getVX/getExpandV2';
import { makeAbsoluteUrl } from '../../../logic/Strings/getSiteCollectionUrlFromLink';
/**
* 2024-09-29: Migrated from src\pnpjs\SourceItems\getSourceItems.ts
*
* getSourceItems calls the Pnp function to get the results which returns the raw error.
* This function then will convert the error into the helpful error and return the standard IItemsError object.
* const UniquePermsFilter = 'HasUniqueRoleAssignments eq true';
* const UniquePermsHiddenFilter = `${ UniquePermsFilter } and Hidden eq false`;
*
* import { getAnalyticsAPI } from "@mikezimm/fps-core-v7/lib/restAPIs/logging/Analytics/getAnalyticsAPI";
*
* @param sourceProps
* @param autoExapnd = true is for normal sourceProps, use false if you have custom logic for expands such as Drilldown
* @param alertMe
* @param consoleLog
* @param expandFormats = optional - use FieldValuesAsText and FieldValuesAsHtml to add to the expands for return format regardless of autoExpand
* @param ItemId -- optional to add a number Id greater than -1 to use the .getById filter, over-rides any restFilter on sourceProps
* @returns
*/
export async function getAnalyticsAPI(fpsSpService, analyticsWeb, analyticsList, WebID, ListID = null, fetchOnlyThisList = false, theseColumns = [], top = 5000, baseErrorTrace) {
// 2024-12-05: Added this because some places like PivotTiles had absoluteWebUrl in webUrl prop... so just taking care of differences
const useUrl = makeAbsoluteUrl(analyticsWeb);
let fetchAPI = `${useUrl}/_api/web/lists/getbytitle('${analyticsList}')/items?`;
if (!useUrl || !analyticsList) {
// NO WebURL... Throw Alert
alert(`${analyticsList} ${SourcePropsNoWebUrl}`);
return createErrorFpsListReturn(useUrl, analyticsList);
}
const selectThese = ['*', 'Author/Name', 'Author/Id', 'Author/Title', 'Author/Office', 'performance', ...theseColumns];
const expandThese = getExpandColumns(selectThese);
let restFilter = !WebID ? '' : `WebID eq '${WebID}'`;
if (fetchOnlyThisList === true && ListID && ListID.length > 0) {
restFilter += ` and ListID eq '${ListID}'`;
}
fetchAPI += `$select=${selectThese.join(',')}`;
fetchAPI += `&$expand=${expandThese.join(',')}`;
const orderBy = createSeriesSort('Id', false);
fetchAPI += `&$orderby=${orderBy.prop} ${orderBy.order}`;
fetchAPI += `&$top=${top}`;
// https://github.com/mikezimm/pivottiles7/issues/429 - 2025-01-06: Was missing rest filter in fetchAPI!
fetchAPI += `&$filter=${restFilter}`;
const result = await doSpHttpFetchOrPostAndCheck(fetchAPI, 'GET', fpsSpService, '', true, true, 'item', false, null);
result.unifiedPerformanceOps.fetch.label = `fetch ${analyticsList}`;
if (check4This(Check4.fpsShowFetchResults_Eq_true) === true) {
console.log(`fps-core-v7 COMPLETE: getSourceItemsAPI ~ 90`, result);
}
;
return result;
}
//# sourceMappingURL=getAnalyticsAPI.js.map