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 EventBus from './EventBus';
|
||||
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 { v4 as uuidv4 } from 'uuid';
|
||||
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) => {
|
||||
this.checkToken().then(() => {
|
||||
const userStore = UserStore.getInstance();
|
||||
@ -310,16 +310,33 @@ export default class MessageBus {
|
||||
const correlationId = uuidv4();
|
||||
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) {
|
||||
return;
|
||||
}
|
||||
unsubscribe();
|
||||
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);
|
||||
});
|
||||
|
||||
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) {
|
||||
return;
|
||||
}
|
||||
@ -329,9 +346,11 @@ export default class MessageBus {
|
||||
});
|
||||
|
||||
this.sendMessage({
|
||||
type: 'CREATE_PROFILE',
|
||||
profileData,
|
||||
accessToken,
|
||||
type: 'CREATE_PROCESS',
|
||||
processData: profileData,
|
||||
privateFields: profilePrivateData,
|
||||
roles,
|
||||
accessToken
|
||||
});
|
||||
}).catch(console.error);
|
||||
});
|
||||
@ -347,14 +366,13 @@ export default class MessageBus {
|
||||
this.initMessageListener(correlationId);
|
||||
|
||||
const unsubscribe = EventBus.getInstance().on('PROCESS_CREATED', (responseId: string, processCreated: any) => {
|
||||
console.log(processCreated);
|
||||
if (responseId !== correlationId) {
|
||||
return;
|
||||
}
|
||||
unsubscribe();
|
||||
this.destroyMessageListener();
|
||||
// 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 (!processCreated.processId || typeof processCreated.processId !== 'string') reject('Returned invalid process id');
|
||||
// TODO check that process is of type Process
|
||||
|
Loading…
x
Reference in New Issue
Block a user