Browse Source

fix(core): Fix error when querying Roles without channels field

Fixes #2693
Michael Bromley 1 year ago
parent
commit
b2cb011f2b
1 changed files with 2 additions and 2 deletions
  1. 2 2
      packages/core/src/service/services/role.service.ts

+ 2 - 2
packages/core/src/service/services/role.service.ts

@@ -70,7 +70,7 @@ export class RoleService {
         relations?: RelationPaths<Role>,
         relations?: RelationPaths<Role>,
     ): Promise<PaginatedList<Role>> {
     ): Promise<PaginatedList<Role>> {
         return this.listQueryBuilder
         return this.listQueryBuilder
-            .build(Role, options, { relations: relations ?? ['channels'], ctx })
+            .build(Role, options, { relations: unique([...(relations ?? []), 'channels']), ctx })
             .getManyAndCount()
             .getManyAndCount()
             .then(async ([items, totalItems]) => {
             .then(async ([items, totalItems]) => {
                 const visibleRoles: Role[] = [];
                 const visibleRoles: Role[] = [];
@@ -92,7 +92,7 @@ export class RoleService {
             .getRepository(ctx, Role)
             .getRepository(ctx, Role)
             .findOne({
             .findOne({
                 where: { id: roleId },
                 where: { id: roleId },
-                relations: relations ?? ['channels'],
+                relations: unique([...(relations ?? []), 'channels']),
             })
             })
             .then(async result => {
             .then(async result => {
                 if (result && (await this.activeUserCanReadRole(ctx, result))) {
                 if (result && (await this.activeUserCanReadRole(ctx, result))) {