Add addCollaborators method to OfficeService
This commit is contained in:
parent
c8f7c3e08e
commit
6f1f542dd2
@ -147,4 +147,43 @@ export default class OfficeService extends AbstractService {
|
|||||||
}).catch(reject);
|
}).catch(reject);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
public static addCollaborators(process: any, existingRoles: any, collaborators: any[]): Promise<void> {
|
||||||
|
return new Promise<void>((resolve: () => void, reject: (error: string) => void) => {
|
||||||
|
const newRoles: any = existingRoles;
|
||||||
|
const owners: string[] = newRoles['owner'].members;
|
||||||
|
if (!owners) {
|
||||||
|
console.error('[addCollaborators] owner role not found');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const previousOwnersLength: number = owners.length;
|
||||||
|
for (const collaborator of collaborators) {
|
||||||
|
if (owners.includes(collaborator)) {
|
||||||
|
console.debug('[addCollaborators] collaborator already in owner role');
|
||||||
|
continue;
|
||||||
|
} else {
|
||||||
|
owners.push(collaborator);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (previousOwnersLength === owners.length) {
|
||||||
|
console.error('[addCollaborators] no new collaborators added');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
console.log('newRoles : ', newRoles);
|
||||||
|
this.messageBus.updateProcess(process.processId, { updated_at: new Date().toISOString() }, [], newRoles).then((processUpdated: any) => {
|
||||||
|
const newStateId: string = processUpdated.diffs[0]?.state_id;
|
||||||
|
this.messageBus.notifyUpdate(process.processId, newStateId).then(() => {
|
||||||
|
this.messageBus.validateState(process.processId, newStateId).then((_stateValidated) => {
|
||||||
|
const officeUid: string = process.processData.uid;
|
||||||
|
this.removeItem('_offices_', officeUid);
|
||||||
|
|
||||||
|
this.getOfficeByUid(officeUid).then(resolve).catch(reject);
|
||||||
|
}).catch(reject);
|
||||||
|
}).catch(reject);
|
||||||
|
}).catch(reject);
|
||||||
|
});
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user