From 71f85d27fad8e1efa2c7037b3d1dca4ec611bf58 Mon Sep 17 00:00:00 2001 From: Daniel Biegler Date: Thu, 14 Nov 2024 15:24:53 +0100 Subject: [PATCH] fix(core): Fix returning stale data in Role Update Event (#3154) --- packages/core/src/service/services/role.service.ts | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/packages/core/src/service/services/role.service.ts b/packages/core/src/service/services/role.service.ts index f551de8bdb..1a1d9f66d6 100644 --- a/packages/core/src/service/services/role.service.ts +++ b/packages/core/src/service/services/role.service.ts @@ -267,7 +267,7 @@ export class RoleService { input.permissions, ); } - const updatedRole = patchEntity(role, { + patchEntity(role, { code: input.code, description: input.description, permissions: input.permissions @@ -275,11 +275,12 @@ export class RoleService { : undefined, }); if (targetChannels) { - updatedRole.channels = targetChannels; + role.channels = targetChannels; } - await this.connection.getRepository(ctx, Role).save(updatedRole, { reload: false }); - await this.eventBus.publish(new RoleEvent(ctx, role, 'updated', input)); - return await assertFound(this.findOne(ctx, role.id)); + await this.connection.getRepository(ctx, Role).save(role, { reload: false }); + const updatedRole = await assertFound(this.findOne(ctx, role.id)); + await this.eventBus.publish(new RoleEvent(ctx, updatedRole, 'updated', input)); + return updatedRole; } async delete(ctx: RequestContext, id: ID): Promise {