Add process udpate in MessageBus
This commit is contained in:
parent
94b6e58cd0
commit
f404054438
@ -406,6 +406,47 @@ export default class MessageBus {
|
||||
});
|
||||
}
|
||||
|
||||
public updateProcess(processId: string, lastStateId: string, newData: Record<string, any>, privateFields: string[], roles: Record<string, RoleDefinition> | null): Promise<any> {
|
||||
return new Promise<any>((resolve: (updatedProcess: any) => void, reject: (error: string) => void) => {
|
||||
this.checkToken().then(() => {
|
||||
const userStore = UserStore.getInstance();
|
||||
const accessToken = userStore.getAccessToken()!;
|
||||
|
||||
const correlationId = uuidv4();
|
||||
this.initMessageListener(correlationId);
|
||||
|
||||
const unsubscribe = EventBus.getInstance().on('PROCESS_UPDATED', (responseId: string, updatedProcess: any) => {
|
||||
console.log('PROCESS_UPDATED', updatedProcess);
|
||||
if (responseId !== correlationId) {
|
||||
return;
|
||||
}
|
||||
unsubscribe();
|
||||
this.destroyMessageListener();
|
||||
resolve(updatedProcess);
|
||||
});
|
||||
|
||||
const unsubscribeError = EventBus.getInstance().on('ERROR_PROCESS_UPDATED', (responseId: string, error: string) => {
|
||||
if (responseId !== correlationId) {
|
||||
return;
|
||||
}
|
||||
unsubscribeError();
|
||||
this.destroyMessageListener();
|
||||
reject(error);
|
||||
});
|
||||
|
||||
this.sendMessage({
|
||||
type: 'UPDATE_PROCESS',
|
||||
processId,
|
||||
lastStateId,
|
||||
newData,
|
||||
privateFields,
|
||||
roles,
|
||||
accessToken
|
||||
});
|
||||
}).catch(console.error);
|
||||
});
|
||||
}
|
||||
|
||||
public notifyProcessUpdate(processId: string, stateId: string): Promise<void> {
|
||||
return new Promise<void>((resolve: () => void, reject: (error: string) => void) => {
|
||||
this.checkToken().then(() => {
|
||||
@ -640,6 +681,18 @@ export default class MessageBus {
|
||||
EventBus.getInstance().emit('STATE_VALIDATED', correlationId, message.validatedProcess);
|
||||
break;
|
||||
|
||||
case 'PROCESS_UPDATED':
|
||||
if (this.errors[correlationId]) {
|
||||
const error = this.errors[correlationId];
|
||||
delete this.errors[correlationId];
|
||||
EventBus.getInstance().emit('ERROR_PROCESS_UPDATED', correlationId, error);
|
||||
return;
|
||||
}
|
||||
console.log('PROCESS_UPDATED', message);
|
||||
EventBus.getInstance().emit('MESSAGE_RECEIVED', message);
|
||||
EventBus.getInstance().emit('PROCESS_UPDATED', correlationId, message.updatedProcess);
|
||||
break;
|
||||
|
||||
case 'ERROR':
|
||||
console.error('Error:', message);
|
||||
this.errors[correlationId] = message.error;
|
||||
|
Loading…
x
Reference in New Issue
Block a user