refactor: Roles out of DB Watcher (#32280)
Co-authored-by: Diego Sampaio <8591547+sampaiodiego@users.noreply.github.com>pull/32405/head
parent
5d1cb28ed9
commit
0154fac0de
@ -0,0 +1,24 @@ |
||||
import { api, dbWatchersDisabled } from '@rocket.chat/core-services'; |
||||
import type { IRole } from '@rocket.chat/core-typings'; |
||||
import { Roles } from '@rocket.chat/models'; |
||||
|
||||
type ClientAction = 'inserted' | 'updated' | 'removed'; |
||||
|
||||
export async function notifyListenerOnRoleChanges( |
||||
rid: IRole['_id'], |
||||
clientAction: ClientAction = 'updated', |
||||
existingRoleData?: IRole, |
||||
): Promise<void> { |
||||
if (!dbWatchersDisabled) { |
||||
return; |
||||
} |
||||
|
||||
const role = existingRoleData || (await Roles.findOneById(rid)); |
||||
|
||||
if (role) { |
||||
void api.broadcast('watch.roles', { |
||||
clientAction, |
||||
role, |
||||
}); |
||||
} |
||||
} |
||||
Loading…
Reference in new issue