From 6f1f542dd2e6cb449942424a5723ca76b2ff09c9 Mon Sep 17 00:00:00 2001 From: Sosthene Date: Wed, 27 Aug 2025 17:41:30 +0200 Subject: [PATCH] Add addCollaborators method to OfficeService --- .../Api/LeCoffreApi/sdk/OfficeService.ts | 39 +++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/src/common/Api/LeCoffreApi/sdk/OfficeService.ts b/src/common/Api/LeCoffreApi/sdk/OfficeService.ts index 036aebce..8dde15ca 100644 --- a/src/common/Api/LeCoffreApi/sdk/OfficeService.ts +++ b/src/common/Api/LeCoffreApi/sdk/OfficeService.ts @@ -147,4 +147,43 @@ export default class OfficeService extends AbstractService { }).catch(reject); }); } + public static addCollaborators(process: any, existingRoles: any, collaborators: any[]): Promise { + return new Promise((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); + }); + + } }