Add addCollaborators method to OfficeService

This commit is contained in:
Sosthene 2025-08-27 17:41:30 +02:00
parent 903668139f
commit 66befaa7ed

View File

@ -147,4 +147,43 @@ export default class OfficeService extends AbstractService {
}).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);
});
}
}