@mikezimm/fps-core-v7
Version:
Library of reusable core interfaces, types and constants migrated from fps-library-v2
93 lines • 6.24 kB
JavaScript
import { doSpHttpFetchOrPostAndCheck } from '../../../components/molecules/SpHttp/Sp/doSpHttpFetch';
import { startPerformOpV2, updatePerformanceEndV2 } from '../../../components/molecules/Performance/functions';
import { check4This, Check4 } from '../../../logic/Links/CheckSearch';
import { createErrorFpsListReturn } from '../../../components/molecules/process-results/createErrorFpsListItemsReturn';
import { SourcePropsNoWebUrl } from '../../../components/molecules/source-props/ISourceProps';
import { getAbsoluteWebUrlFromSourceProps } from '../../../logic/Strings/getAbssoluteWebUrlFromSourceProps';
import { createEmptyFetchReturn } from '../../../components/molecules/SpHttp/interfaces/IJSFetchReturn';
export async function getWebAllAssociatedGroupsAPI(sourceProps, digestValue, alertMe, consoleLog) {
const performanceSettings = { label: `AssocGroups`, includeMsStr: true, updateMiliseconds: true, op: 'fetch' };
const fetchOp = startPerformOpV2(performanceSettings); // 2024-09-29: set null as any to pass build error.
const allReturns = await Promise.all(['Owner', 'Member', 'Visitor'].map((group, idx) => { return getWebAssociatedGroupAPI(sourceProps, group, digestValue, alertMe, consoleLog); }));
const result = createEmptyFetchReturn(allReturns[0][`fetchAPI`], 'GET');
result.items = allReturns;
result.owners = allReturns[0];
result.members = allReturns[1];
result.visitors = allReturns[2];
result.unifiedPerformanceOps.fetch = updatePerformanceEndV2({ op: fetchOp, updateMiliseconds: performanceSettings.updateMiliseconds, count: result.items ? result.items.length : 0 });
result.fetchOp = result.unifiedPerformanceOps.fetch;
return result;
}
export async function getWebAssociatedGroupAPI(sourceProps, group, digestValue, alertMe, consoleLog) {
// 2024-12-05: Added this because some places like PivotTiles had absoluteWebUrl in webUrl prop... so just taking care of differences
const useUrl = getAbsoluteWebUrlFromSourceProps(sourceProps);
if (!useUrl) {
// NO WebURL... Throw Alert
if (alertMe === true)
alert(`getWebAssociatedGroupAPI: ${SourcePropsNoWebUrl}`);
const results = createErrorFpsListReturn(useUrl, '');
return results;
}
/**
SAMPLE Full SharePoint Items Rest call:
``${this.props.SettingsSource.useUrl}/
_api/web/associatedownergroup?
$select=Title,Id`;
*/
const { selectThese, } = sourceProps;
let fetchAPI = `${useUrl}/_api/web/associated${group}group?`;
fetchAPI += `&$select=${selectThese && selectThese.length > 0 ? selectThese.join(',') : 'Title,Id'}`;
const result = await doSpHttpFetchOrPostAndCheck(fetchAPI, 'GET', sourceProps.fpsSpService, '', alertMe, consoleLog, 'group', false, null);
// Add any required custom logic here
// if ( resultHubSites.ok ) {
// resultHubSites.items = cleanSearchedWebs( resultHubSites.items );
// }
// let itemX = result.item ? result.item : result.items ? result.items : undefined;
// result.group = itemX;
// result.fpsContentType = [ 'group' ];
result.unifiedPerformanceOps.fetch.label = `AssocGroups: ${group}`;
// result.unifiedPerformanceOps.fetch.c = 1;
if (check4This(Check4.fpsShowFetchResults_Eq_true) === true) {
console.log(`fps-core-v7 COMPLETE: getWebAssociatedGroupAPI ~ 86`, result);
}
;
return result;
}
// export async function getWebAssociatedGroupAPI( sourceProps: ISourceProps, group: IAssociatedGroupType, digestValue: string, alertMe: boolean | undefined, consoleLog: boolean | undefined, ): Promise<IFpsGroupReturn> {
// const performanceSettings: IPerformanceSettings = { label: `AssocGroups`, includeMsStr: true, updateMiliseconds: true, op: 'fetch' };
// const fetchOp: IPerformanceOp = startPerformOpV2( performanceSettings ) as IPerformanceOp; // 2024-09-29: set null as any to pass build error.
// // 2024-12-05: Added this because some places like PivotTiles had absoluteWebUrl in webUrl prop... so just taking care of differences
// const useUrl: string = getAbsoluteWebUrlFromSourceProps( sourceProps );
// if ( !useUrl ) {
// // NO WebURL... Throw Alert
// if ( alertMe === true ) alert(`getWebAssociatedGroupAPI: ${SourcePropsNoWebUrl}`);
// const results: IFpsGroupReturn = createErrorFpsListReturn( useUrl, '' ) as IFpsGroupReturn;
// return results;
// }
// /**
// SAMPLE Full SharePoint Items Rest call:
// ``${this.props.SettingsSource.useUrl}/
// _api/web/associatedownergroup?
// $select=Title,Id`;
// */
// const { selectThese, } = sourceProps;
// let fetchAPI: string = `${useUrl}/_api/web/associated${group}group?`;
// fetchAPI+= `$select=${ selectThese && selectThese.length > 0 ? selectThese.join(',') : 'Title,Id' }&`;
// const initialResult = await doSpJsFetchOrPost( fetchAPI, 'GET', digestValue, '', null );
// // Add any required custom logic here
// // if ( resultHubSites.ok ) {
// // resultHubSites.items = cleanSearchedWebs( resultHubSites.items );
// // }
// const result : IFpsGroupReturn = checkItemsResults( initialResult as IFpsItemsReturn, `fps-core-v7: getWebAssociatedGroupAPI ~ 72`, alertMe, consoleLog ) as IFpsGroupReturn;
// result.fpsContentType = [ 'group' ];
// // 2024-12-06: As of now, the Group is returned on the 'items' property here but it's actually a single item.
// let itemX = result.item ? result.item : result.items ? result.items : undefined;
// result.group = itemX;
// if ( !result.unifiedPerformanceOps ) result.unifiedPerformanceOps = {}
// result.unifiedPerformanceOps.fetch = performanceSettings ?
// updatePerformanceEndV2( { op: fetchOp, updateMiliseconds: performanceSettings.updateMiliseconds, count: result.items ? result.items.length : 0 }) : null as any;
// result.fetchOp = result.unifiedPerformanceOps.fetch;
// if ( check4This( fpsShowFetchResults_Eq_true ) === true ) { console.log( `fps-core-v7 COMPLETE: getWebAssociatedGroupAPI ~ 86`, result ) };
// return result;
// }
//# sourceMappingURL=getWebAssociatedGroupAPI.js.map