diff --git a/src/services/service.ts b/src/services/service.ts index 9c9bdb6..3a0bdf8 100755 --- a/src/services/service.ts +++ b/src/services/service.ts @@ -946,7 +946,45 @@ export default class Services { } } + async getDescription(processId: string, process: Process): Promise { + const service = await Services.getInstance(); + // Get the `commited_in` value of the last state and remove it from the array + const currentCommitedIn = process.states.at(-1)?.commited_in; + console.log('Current CommitedIn:' currentCommitedIn) + if (currentCommitedIn === undefined) { + return null; // No states available + } + + // Find the last state where `commited_in` is different + let lastDifferentState = process.states.findLast( + state => state.commited_in !== currentCommitedIn + ); + + if (!lastDifferentState) { + // It means that we only have one state that is not commited yet, that can happen with process we just created + // let's assume that the right description is in the last concurrent state and not handle the (arguably rare) case where we have multiple concurrent states on a creation + lastDifferentState = process.states.at(-1); + } + + if (!lastDifferentState.pcd_commitment) { + return null; + } + + // Take the description out of the state, if any + const description = lastDifferentState!.pcd_commitment['description']; + if (description) { + const userDiff = await service.getDiffByValue(description); + if (userDiff) { + console.log("Successfully retrieved userDiff:", userDiff); + return userDiff.new_value; + } else { + console.log("Failed to retrieve a non-null userDiff."); + } + } + + return null; + } getNotifications(): any[] | null { // return [