Make createProfile compatible with CREATE_PROCESS interface
This commit is contained in:
parent
2084b99978
commit
7807ae315f
@ -1,7 +1,7 @@
|
|||||||
import IframeReference from './IframeReference';
|
import IframeReference from './IframeReference';
|
||||||
import EventBus from './EventBus';
|
import EventBus from './EventBus';
|
||||||
import UserStore from './UserStrore';
|
import UserStore from './UserStrore';
|
||||||
import type { ProfileCreated, ProfileData } from './models/ProfileData';
|
import { isProfileData, type ProfileCreated, type ProfileData } from './models/ProfileData';
|
||||||
import { isFolderData, type FolderCreated, type FolderData } from './models/FolderData';
|
import { isFolderData, type FolderCreated, type FolderData } from './models/FolderData';
|
||||||
import { v4 as uuidv4 } from 'uuid';
|
import { v4 as uuidv4 } from 'uuid';
|
||||||
import type { RoleDefinition } from './models/Roles';
|
import type { RoleDefinition } from './models/Roles';
|
||||||
@ -301,7 +301,7 @@ export default class MessageBus {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public createProfile(profileData: ProfileData): Promise<ProfileCreated> {
|
public createProfile(profileData: ProfileData, profilePrivateData: string[], roles: Record<string, RoleDefinition>): Promise<ProfileCreated> {
|
||||||
return new Promise<ProfileCreated>((resolve: (profileCreated: ProfileCreated) => void, reject: (error: string) => void) => {
|
return new Promise<ProfileCreated>((resolve: (profileCreated: ProfileCreated) => void, reject: (error: string) => void) => {
|
||||||
this.checkToken().then(() => {
|
this.checkToken().then(() => {
|
||||||
const userStore = UserStore.getInstance();
|
const userStore = UserStore.getInstance();
|
||||||
@ -310,16 +310,33 @@ export default class MessageBus {
|
|||||||
const correlationId = uuidv4();
|
const correlationId = uuidv4();
|
||||||
this.initMessageListener(correlationId);
|
this.initMessageListener(correlationId);
|
||||||
|
|
||||||
const unsubscribe = EventBus.getInstance().on('PROFILE_CREATED', (responseId: string, profileCreated: ProfileCreated) => {
|
const unsubscribe = EventBus.getInstance().on('PROCESS_CREATED', (responseId: string, processCreated: any) => {
|
||||||
if (responseId !== correlationId) {
|
if (responseId !== correlationId) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
unsubscribe();
|
unsubscribe();
|
||||||
this.destroyMessageListener();
|
this.destroyMessageListener();
|
||||||
|
// Return value must contain the data commited in the new process
|
||||||
|
const profileData = processCreated.processData;
|
||||||
|
if (!profileData || !isProfileData(profileData)) {
|
||||||
|
reject('Returned invalid profile data');
|
||||||
|
}
|
||||||
|
if (!processCreated.processId || typeof processCreated.processId !== 'string') {
|
||||||
|
console.error('Returned invalid process id');
|
||||||
|
reject('Returned invalid process id');
|
||||||
|
}
|
||||||
|
// TODO check that process is of type Process
|
||||||
|
|
||||||
|
const profileCreated: ProfileCreated = {
|
||||||
|
processId: processCreated.processId,
|
||||||
|
process: processCreated.process,
|
||||||
|
profileData
|
||||||
|
};
|
||||||
|
|
||||||
resolve(profileCreated);
|
resolve(profileCreated);
|
||||||
});
|
});
|
||||||
|
|
||||||
const unsubscribeError = EventBus.getInstance().on('ERROR_PROFILE_CREATED', (responseId: string, error: string) => {
|
const unsubscribeError = EventBus.getInstance().on('ERROR_PROCESS_CREATED', (responseId: string, error: string) => {
|
||||||
if (responseId !== correlationId) {
|
if (responseId !== correlationId) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -329,9 +346,11 @@ export default class MessageBus {
|
|||||||
});
|
});
|
||||||
|
|
||||||
this.sendMessage({
|
this.sendMessage({
|
||||||
type: 'CREATE_PROFILE',
|
type: 'CREATE_PROCESS',
|
||||||
profileData,
|
processData: profileData,
|
||||||
accessToken,
|
privateFields: profilePrivateData,
|
||||||
|
roles,
|
||||||
|
accessToken
|
||||||
});
|
});
|
||||||
}).catch(console.error);
|
}).catch(console.error);
|
||||||
});
|
});
|
||||||
@ -347,14 +366,13 @@ export default class MessageBus {
|
|||||||
this.initMessageListener(correlationId);
|
this.initMessageListener(correlationId);
|
||||||
|
|
||||||
const unsubscribe = EventBus.getInstance().on('PROCESS_CREATED', (responseId: string, processCreated: any) => {
|
const unsubscribe = EventBus.getInstance().on('PROCESS_CREATED', (responseId: string, processCreated: any) => {
|
||||||
console.log(processCreated);
|
|
||||||
if (responseId !== correlationId) {
|
if (responseId !== correlationId) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
unsubscribe();
|
unsubscribe();
|
||||||
this.destroyMessageListener();
|
this.destroyMessageListener();
|
||||||
// Return value must contain the data commited in the new process
|
// Return value must contain the data commited in the new process
|
||||||
const folderData = processCreated.folderCreated;
|
const folderData = processCreated.processData;
|
||||||
if (!folderData || !isFolderData(folderData)) reject('Returned invalid process data');
|
if (!folderData || !isFolderData(folderData)) reject('Returned invalid process data');
|
||||||
if (!processCreated.processId || typeof processCreated.processId !== 'string') reject('Returned invalid process id');
|
if (!processCreated.processId || typeof processCreated.processId !== 'string') reject('Returned invalid process id');
|
||||||
// TODO check that process is of type Process
|
// TODO check that process is of type Process
|
||||||
|
Loading…
x
Reference in New Issue
Block a user