Add getDescription to Services

This commit is contained in:
NicolasCantu 2025-01-22 17:17:28 +01:00
parent 1b0f4783f6
commit f50bdafc80

View File

@ -946,7 +946,45 @@ export default class Services {
} }
} }
async getDescription(processId: string, process: Process): Promise<string | null> {
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 { getNotifications(): any[] | null {
// return [ // return [