@mikezimm/fps-core-v7
Version:
Library of reusable core interfaces, types and constants migrated from fps-library-v2
71 lines (68 loc) • 3.47 kB
JavaScript
import { doSpHttpFetchOrPostAndCheck } from '../../../components/molecules/SpHttp/Sp/doSpHttpFetch';
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 { getCollectionUrl } from '../../../logic/Links/getSPOUrl';
/**
* To get a parent node, this is the filter structure you want to include (without including the $filter=)
$filter= `ParentNodeId eq ${ParentNodeId}`
To create a childNavigationNode, just pass in the parentNodeId as a parameter (not in the body)
NOTE: This api currently needs to use Odata V3. At least I think it does based on pnpjs v2
* 2024-12-29: Has been moved to fps-core-v7
* import { getOrAddWebNavAPI, } from "@mikezimm/fps-core-v7/lib/restAPIs/sites/nav/getOrAddWebNavAPI";
*
* @param sourceProps
* @param location
* @param alertMe
* @param consoleLog
* @param body
* @returns
*/
export async function getOrAddWebNavAPI(sourceProps, method, location, alertMe, consoleLog, body, parentNodeId = -1) {
const { restFilter, selectThese = [] } = sourceProps;
let useUrl = getAbsoluteWebUrlFromSourceProps(sourceProps);
if (!useUrl) {
// NO WebURL... Throw Alert
if (alertMe === true)
alert(`getOrAddWebNavAPI: ${SourcePropsNoWebUrl}`);
const results = createErrorFpsListReturn(useUrl, '');
return results;
}
/**
SAMPLE Full SharePoint Items Rest call:
``${this.props.SettingsSource.useUrl}/
_api/web/sitegroups?
$filter=startswith(Title,'EULA')&
$select=Title,Id`;
*/
// https://github.com/fps-solutions/HubCon/issues/121 - remove the space (%20) after quicklaunch
let fetchAPI = `${useUrl}/_api/web/navigation/${location == 'Quicklaunch' ? 'quicklaunch' : 'topnavigationbar'}`;
if (parentNodeId > -1) {
fetchAPI += `(${parentNodeId})/children`;
}
if (body && body.Id) {
fetchAPI += `(${body.Id})`;
}
// Need the (body as any) syntax because Id is required on the body interface... so it does not want you to delete itl
if (body && body.Id)
delete body.Id;
fetchAPI += `?`;
if (method === 'GET') {
fetchAPI += `&$orderby=Title asc`;
fetchAPI += `&$select=${selectThese.length > 0 ? selectThese.join(',') : '*'}`;
// As of 2024-12-29: Navigation does not currently have any expandable properties
// const expandThese: string[] = getExpandColumns( selectThese );
// if ( expandThese.length > 0 ) fetchAPI+= `$expand=${ expandThese.join(',') }&`;
if (restFilter)
fetchAPI += `&$filter=${restFilter}`;
}
const result = await doSpHttpFetchOrPostAndCheck(fetchAPI, method, sourceProps.fpsSpService, '', alertMe, consoleLog, 'navItem', false, body);
result.unifiedPerformanceOps.fetch.label = `${getCollectionUrl(useUrl)} ${location}Nav`;
if (check4This(Check4.fpsShowFetchResults_Eq_true) === true) {
console.log(`fps-core-v7 COMPLETE: getOrAddWebNavAPI ~ 60`, result);
}
;
return result;
}
//# sourceMappingURL=getOrAddWebNavAPI.js.map