@mikezimm/fps-core-v7
Version:
Library of reusable core interfaces, types and constants migrated from fps-library-v2
75 lines (73 loc) • 4.43 kB
JavaScript
/**
* CodeAnalizerComment: Updated 3 imports on 2024-09-22 14:49:52
* Update:: import { IFPSItemUpdateResultObj } to '@mikezimm/fps-core-v7/lib/types/fps-returns/sites/update/IFPSItemUpdateResultObj;'
* Update:: import { CommandUpdateFailedMessage } to '@mikezimm/fps-core-v7/lib/components/webparts/Drilldown/QuickCommands/IQuickCommands;'
* Update:: import { IFpsErrorObject } to '@mikezimm/fps-core-v7/lib/types/fps-returns/common/IFpsErrorObject;'
*/
/**
* CodeAnalizerComment: Updated 8 imports on 2024-09-21 23:07:24
* Update:: import { convertHelpfullError } to '@mikezimm/fps-core-v7/lib/logic/Errors/friendly;'
* Update:: import { IFPSItemUpdateResultObj } to '@mikezimm/fps-core-v7/lib/types/fps-returns/sites/update/IFPSItemUpdateResultObj;'
* Update:: import { IMinUpdateProps } to '@mikezimm/fps-core-v7/lib/types/fps-returns/sites/update/IMinUpdateProps;'
* Update:: import { saveErrorToLog } to '@mikezimm/fps-core-v7/lib/components/molecules/process-results/Logging;'
* Update:: import { IFpsErrorObject } to '@mikezimm/fps-core-v7/lib/types/fps-returns/common/IFpsErrorObject;'
* Update:: import { startPerformOpV2 } to '@mikezimm/fps-core-v7/lib/components/molecules/Performance/functions;'
* Update:: import { updatePerformanceEndV2 } to '@mikezimm/fps-core-v7/lib/components/molecules/Performance/functions;'
* Update:: import { IStartPerformOp } to '@mikezimm/fps-core-v7/lib/components/molecules/Performance/IPerformanceSettings;'
*/
import { startPerformOpV2, updatePerformanceEndV2 } from '../../../components/molecules/Performance/functions';
import { CommandUpdateFailedMessage } from '../../../components/webparts/Drilldown/QuickCommands/IQuickCommands';
import { saveErrorToLog } from '../../logging/Errors/saveErrorToLog';
import { updateAnyItemAPI } from './updateAnyItemAPI';
/**
* 2024-12-09: Migrated from fps-library-v2...
* Currently untested, but use this fetch:
* import { IUpdateCommandItemProps, IUpdateCommandItemReturn, updateCommandItemAPI, } from '@mikezimm/fps-core-v7/lib/restAPIS/lists/items/updateCommandItemAPI';
*
* @param commandItemProps
* @returns
*/
export async function updateCommandItemAPI(commandItemProps) {
/**
* 2024-12-14: REMOVE THIS after testing since
* updateAnyItemAPI calls doSpHttpFetchOrPostAndCheck which includes performance out of the box
*/
const performanceSettings = {
label: `updateItem ~ saveOp`,
includeMsStr: true,
};
const saveOp = performanceSettings ? startPerformOpV2(performanceSettings) : null;
const { itemUpdate, Id, alertMe, consoleLog } = commandItemProps;
const finalResult = await updateAnyItemAPI(commandItemProps, itemUpdate, Id, false, false);
finalResult.webUrl = commandItemProps.webUrl;
finalResult.listTitle = commandItemProps.listTitle;
finalResult.Id = commandItemProps.Id;
if (finalResult.status === 'Success') {
if (alertMe) {
alert('Success!\n' + alertMe);
}
if (consoleLog) {
console.log(consoleLog, finalResult);
}
}
else if (finalResult.status === 'Error') {
// 2024-12-09: This saveErrorToLog may be executed twice because checkItemsResults executes the save if it's not a standard error from FPSResultCommonErrors
saveErrorToLog(finalResult.errorInfo, finalResult.errorInput, commandItemProps.fpsSpService);
let errMessage = `${CommandUpdateFailedMessage} - ${finalResult.errorInfo ? finalResult.errorInfo.friendly : ''}`;
if (alertMe) {
alert(`${CommandUpdateFailedMessage}\n${alertMe}\n${errMessage}`);
}
console.log(`${CommandUpdateFailedMessage}\n${consoleLog}\n${errMessage}`);
}
else {
alert(`updateCommandItems ~ 50 - result.status = ${finalResult.status}`);
}
// https://github.com/fps-solutions/Rtf-Fixer/issues/30
if (!finalResult.unifiedPerformanceOps)
finalResult.unifiedPerformanceOps = {};
finalResult.unifiedPerformanceOps.save = updatePerformanceEndV2({ op: saveOp, updateMiliseconds: true, count: 1 });
// If performance is removed from here (cause it's done in the fetch op, keep this to bring it back up to saveOp)
finalResult.saveOp = finalResult.unifiedPerformanceOps.save;
return finalResult;
}
//# sourceMappingURL=updateCommandItemAPI.js.map