@mikezimm/fps-core-v7
Version:
Library of reusable core interfaces, types and constants migrated from fps-library-v2
71 lines (70 loc) • 3.25 kB
JavaScript
import { SourcePropsNoListTitle, 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 { getAbsoluteWebUrlFromSourceProps } from '../../../logic/Strings/getAbssoluteWebUrlFromSourceProps';
/**
* 2024-12-09: Migrated from fps-Pnp2...
* Currently untested, but use this fetch:
* import { updateAnyItemAPI } from '@mikezimm/fps-core-v7/lib/restAPIS/lists/items/updateAnyItemAPI';
*
* 2024-12-09: Created this in order to update any list type items.
* For instance, use by updateCommandItems to update simple list items in SPO
*
* @param sourceProps
* @param saveItem
* @param itemId
* @param alertMe
* @param consoleLog
* @returns
*/
export async function updateAnyItemAPI(sourceProps, saveItem, itemId, alertMe, consoleLog) {
const { listTitle, } = sourceProps;
// 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);
/**
SAMPLE Full SharePoint Items Rest call:
https://example.sharepoint.com/sites/MySite/_api/web/lists/getbytitle('MyList')/items
*/
if (!useUrl) {
// NO WebURL... Throw Alert
if (alertMe === true)
alert(`${listTitle} ${SourcePropsNoWebUrl}`);
return createErrorFpsListReturn(useUrl, listTitle);
}
if (!listTitle) {
// NO WebURL... Throw Alert
if (alertMe === true)
alert(`${''} ${SourcePropsNoListTitle}`);
return createErrorFpsListReturn(useUrl, listTitle);
}
let postAPI = `${useUrl}/_api/web/lists/getbytitle('${listTitle}')/items(${itemId})`;
/**
* Use 'MERGE' for updating items
*/
/**
*
*
* COMPARE THIS TO ORIGINAL LOGIC FOR updating command items
*
*
*
*/
const result = await doSpHttpFetchOrPostAndCheck(postAPI, 'MERGE', sourceProps.fpsSpService, '', alertMe, consoleLog, 'item', false, saveItem);
// Add any required custom logic here
// if ( resultHubSites.ok ) {
// resultHubSites.items = cleanSearchedWebs( resultHubSites.items );
// }
// result.fpsContentType = !sourceProps.fpsContentType ? [ 'item' ] : sourceProps.fpsContentType;
// 2024-12-05: changed if to test result, not sourceProps... was getting error reading indexOf
// if ( result.fpsContentType.indexOf( 'item' ) < 0 ) result.fpsContentType.push( 'item' );
result.unifiedPerformanceOps.fetch.label = `update ${listTitle}`;
// result.unifiedPerformanceOps.fetch.c = 1;
result.saveOp = result.unifiedPerformanceOps.fetch;
if (check4This(Check4.fpsShowFetchResults_Eq_true) === true) {
console.log(`fps-core-v7 COMPLETE: postSourceItems ~ 56`, result);
}
;
return result;
}
//# sourceMappingURL=updateAnyItemAPI.js.map