@mikezimm/fps-core-v7
Version:
Library of reusable core interfaces, types and constants migrated from fps-library-v2
67 lines (66 loc) • 4.75 kB
JavaScript
/**
* 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';
/**
* This will fetch Subsites and their site logos, be sure to run EasyIcons after
* It does two fetches at the same time syncronosly.... needed due to SPO rest limiations.
* - apiSearchWebs api uses Search to find all subsites of the parent Url in order to get the actual SiteLogs
* - apiFilteredWebs api gets the actual current subsites the user has access to FOR THE CURRENT WEB.
* - Technically you could just use Search but that requires a crawl which may result in returning items that have been changed or deleted.
* Used in Pivot Tiles and Hub Connections.
*
* @param webUrl
* @param departmentId
* @returns
*/
export async function fetchMySubsites(fpsSpService, webUrl) {
let performanceSettings = { label: 'mySubs', updateMiliseconds: true, includeMsStr: true, op: 'fetch' };
const fetchOp = performanceSettings ? startPerformOpV2(performanceSettings) : null;
const apiSearchWebs = `${webUrl}/_api/search/query?querytext='ParentLink=${webUrl} contentclass:STS_Web'&selectproperties='${hubSelects.join(',')}'&rowlimit=200`;
const apiFilteredWebs = `${webUrl}/_api/web/getsubwebsfilteredforcurrentuser(nwebtemplatefilter=-1,nconfigurationfilter=0)`;
let [searchedWebs, filteredWebs,] = await Promise.all([
doSpHttpFetchOrPostAndCheck(apiSearchWebs, 'GET', fpsSpService, '', false, true, 'web', false, null),
doSpHttpFetchOrPostAndCheck(apiFilteredWebs, 'GET', fpsSpService, '', false, true, 'web', false, null),
]);
// 2025-01-20: Removed since it's now done automatically in the fetch wrapper: https://github.com/mikezimm/pivottiles7/issues/433
// if ( searchedWebs.ok ) searchedWebs.items = cleanSearchedWebs( searchedWebs.items as IFPSWebsWithLogo[] );
const resultWebs = [];
// Search through the fetched webs and try to find SiteLogos from Search
if (filteredWebs.items)
filteredWebs.items.map(filteredWeb => {
const matchedWeb = searchedWebs.items ? searchedWebs.items.filter(cleanedWeb => { return cleanedWeb.ServerRelativeUrl === filteredWeb.ServerRelativeUrl; }) : [];
if (matchedWeb.length) {
// Added to support: https://github.com/mikezimm/pivottiles7/issues/289
const LastItemUserModifiedDate = filteredWeb.LastItemUserModifiedDate ? `${filteredWeb.LastItemUserModifiedDate}` : undefined;
filteredWeb = { ...filteredWeb, ...matchedWeb[0] };
filteredWeb.LastItemUserModifiedDate = LastItemUserModifiedDate; // Add this back after merging because matchedWeb does not have it.
}
resultWebs.push(filteredWeb);
});
searchedWebs.items = resultWebs;
// Go back and update searchWebs status if filteredWebs is not ok
if (filteredWebs.ok !== true)
searchedWebs.ok = filteredWebs.ok;
if (filteredWebs.ok !== true)
searchedWebs.status = filteredWebs.status;
if (filteredWebs.ok !== true)
searchedWebs.statusText = filteredWebs.statusText;
let result = unifiedPerformanceEnd(searchedWebs, performanceSettings, fetchOp, 'fetch', 'items');
result.unifiedPerformanceOps.fetch1 = searchedWebs.unifiedPerformanceOps.fetch;
result.unifiedPerformanceOps.fetch1.label = `fetch1a searchedWebs`;
result.unifiedPerformanceOps.fetch2 = filteredWebs.unifiedPerformanceOps.fetch;
result.unifiedPerformanceOps.fetch2.label = `fetch1a filteredWebs`;
result = checkItemsResults(fpsSpService, result, `fps-library-v2: fetchMySubsites ~ 62`, false, true);
result.fpsContentType = ['web'];
return result;
}
//# sourceMappingURL=fetchMySubsites.js.map