UNPKG

@mikezimm/fps-core-v7

Version:

Library of reusable core interfaces, types and constants migrated from fps-library-v2

87 lines (86 loc) 6.59 kB
/** * CodeAnalizerComment: Updated 5 imports on 2024-09-22 14:49:52 * Update:: import { IJSFetchReturn } to '@mikezimm/fps-core-v7/lib/components/molecules/SpHttp/doSpJsFetch;' * Update:: import { doSpJsFetch } to '@mikezimm/fps-core-v7/lib/components/molecules/SpHttp/doSpJsFetch;' * Update:: import { IFpsErrorObject } to '@mikezimm/fps-core-v7/lib/types/fps-returns/common/IFpsErrorObject;' * Update:: import { IFpsItemsReturn } to '@mikezimm/fps-core-v7/lib/components/molecules/process-results/CheckItemsResults;' * Update:: import { checkItemsResults } to '@mikezimm/fps-core-v7/lib/components/molecules/process-results/CheckItemsResults;' */ import { doSpHttpFetchOrPostAndCheck } from '../../../../components/molecules/SpHttp/Sp/doSpHttpFetch'; import { hubSelects } from '../interfaces/IFPSHubSiteDataDocsApi'; import { startPerformOpV2, unifiedPerformanceEnd } from '../../../../components/molecules/Performance/functions'; import { checkItemsResults } from '../../../../components/molecules/process-results/CheckWService/CheckItemsResults'; /** * fetchMyHubsites will fetch an array of the current site's hub associated sites. Used in Pivot Tiles and Hub Connections. * @param webUrl * @param departmentId * @returns */ // export type IFetchHubDepth = 'site' | 'web'; // export async function fetchMyHubsites( webUrl: string, depth: IFetchHubDepth, departmentId: string ): Promise<IJSFetchReturn> { // const performanceSettings: IPerformanceSettings = { label: 'myHubs', updateMiliseconds: true, includeMsStr: true, op: 'fetch' }; // const fetchOp = performanceSettings ? startPerformOpV2( performanceSettings ) : null; // const apiFetchAssociatedHubs: string = `${webUrl}/_api/search/query?querytext='DepartmentId=${departmentId} contentclass:sts_${depth} -SiteId:${departmentId}'&selectproperties='${hubSelects.join(',')}'&rowlimit=${depth==='site'?200:500}`;// 9 Works // const resultHubSites: IJSFetchReturn = await doSpJsFetch( apiFetchAssociatedHubs ); // if ( resultHubSites.ok ) resultHubSites.items = cleanSearchedWebs( resultHubSites.items ); // let result : IJSFetchReturn = unifiedPerformanceEnd( resultHubSites as IFpsErrorObject, performanceSettings, fetchOp, 'fetch', 'items' ) as IJSFetchReturn; // result.fpsContentType = [ depth ]; // result = checkItemsResults( result as IFpsItemsReturn, `fps-library-v2: fetchMyHubsites ~ 30`, false, true ) as IJSFetchReturn; // return resultHubSites; // } import { NonGroupGroupID } from '../functions/processHubSubResults'; /** * fetchMyHubsites imported from HubCon on 2024-07-29. * @param webUrl * @param depth IFetchHubDepth = 'site' | 'web'; * @param departmentId * @param filter IHubFilterType = 'Associated' | 'Hubs' | 'Teams' | 'HubAndAssoc'; * @returns */ export async function fetchMyHubsites(fpsSpService, webUrl, depth, departmentId, filter, maxRows = 500) { const performanceSettings = { label: 'myHubs', updateMiliseconds: true, includeMsStr: true, op: 'fetch' }; const fetchOp = performanceSettings ? startPerformOpV2(performanceSettings) : null; const minSearch = `${webUrl}/_api/search/query?querytext='DepartmentId=`; const minSelectRowLimit = `'&selectproperties='${hubSelects.join(',')}'&rowlimit=`; // 2024-12-22: digestValue not required when using SpHTTPClient // const digestValue = await getThisFPSDigestValueFromUrl( webUrl ); // -SiteId:${departmentId} let fetchAPIStr = ``; // if ( filter === 'Associated' ) { fetchAPIStr = `${minSearch}${departmentId} contentclass:sts_${depth} -SiteId:${departmentId} ${ minSelectRowLimit }${depth==='site'?200:500}`; // 9 Works if (filter === 'Associated') { fetchAPIStr = `${minSearch}${departmentId} contentclass:sts_${depth} -SiteId:${departmentId}'&selectproperties='${hubSelects.join(',')}'&rowlimit=${depth === 'site' ? maxRows : maxRows * 2}`; // 9 Works } if (filter === 'HubAndAssoc') { fetchAPIStr = `${minSearch}${departmentId} contentclass:sts_${depth}'&selectproperties='${hubSelects.join(',')}'&rowlimit=${depth === 'site' ? maxRows : maxRows * 2}`; // 9 Works // https://github.com/fps-solutions/HubCon/issues/133 } if (filter === 'Hubs') { fetchAPIStr = `${minSearch}* contentclass:sts_site ${minSelectRowLimit}${maxRows}`; // 9 Works // https://github.com/fps-solutions/HubCon/issues/133 } if (filter === 'NonGroups') { fetchAPIStr = `${minSearch}* contentclass:sts_site (GroupId:"${NonGroupGroupID}" OR NOT GroupId:*)" ${minSelectRowLimit}${maxRows}`; // 9 Works } if (filter === 'Teams') { fetchAPIStr = `${minSearch}* contentclass:sts_site -GroupId:"${NonGroupGroupID}" ${minSelectRowLimit}${maxRows}`; // 9 Works // } if ( filter === 'AllChildSubs' ) { fetchAPIStr = `${minSearch}* contentclass:sts_site -GroupId:"${NonGroupGroupID}" ${ minSelectRowLimit }${500}`;// 9 Works // } if ( filter === 'DirectChildren' ) { fetchAPIStr = `${minSearch}* contentclass:sts_site -GroupId:"${NonGroupGroupID}" ${ minSelectRowLimit }${500}`;// 9 Works } // fetchAPIStr = `${webUrl}/_api/search/query?querytext='DepartmentId=${departmentId} contentclass:sts_${depth} -SiteId:${departmentId}'&selectproperties='${hubSelects.join(',')}'&rowlimit=${depth==='site'?200:500}`;// 9 Works // fetchAPIStr = `${minSearch}/${departmentId} contentclass:sts_${depth} -SiteId:${departmentId}'&selectproperties='${hubSelects.join(',')}'&rowlimit=${depth==='site'?200:500}`;// 9 Works const resultHubSites = await doSpHttpFetchOrPostAndCheck(fetchAPIStr, 'GET', fpsSpService, '', false, true, 'hub', false, null); // 2025-01-20: Removed since it's now done automatically in the fetch wrapper: https://github.com/mikezimm/pivottiles7/issues/433 // if ( resultHubSites.ok ) { // resultHubSites.items = cleanSearchedWebs( resultHubSites.items ); // } if (filter === 'Hubs') { resultHubSites.allHubs = resultHubSites.items.filter(item => item.DepartmentId.indexOf(item.SiteId) === 1); //https://github.com/fps-solutions/HubCon/issues/23 resultHubSites.allHubs.sort((a, b) => a.Title.localeCompare(b.Title)); } let result = unifiedPerformanceEnd(resultHubSites, performanceSettings, fetchOp, 'fetch', 'items'); result.fpsContentType = [depth]; result = checkItemsResults(fpsSpService, result, `fps-library-v2: fetchMyHubsites ~ 30`, false, true); return resultHubSites; } //# sourceMappingURL=fetchMyHubsites.js.map