Skip to content

Commit

Permalink
fix(core): Fix test where administrator service needs to throw for in…
Browse files Browse the repository at this point in the history
…valid role id
  • Loading branch information
DanielBiegler committed Nov 26, 2024
1 parent b32642b commit 9fb95b9
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ export class ChannelRolePermissionResolverStrategy implements RolePermissionReso
roleIds.length === 0
? []
: await this.connection.getRepository(ctx, Role).findBy(roleIds.map(id => ({ id })));
for (const roleId of roleIds) {
const foundRole = roles.find(role => role.id === roleId);
if (!foundRole) throw new EntityNotFoundError('Role', roleId);
}

// TODO we are relying here on the `roles` relation existing, it could be missing if you query
// user entries without supplying the relations argument, for example:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { ID } from '@vendure/common/lib/shared-types';

import { RequestContext } from '../../api';
import { Injector } from '../../common';
import { EntityNotFoundError, Injector } from '../../common';
import { TransactionalConnection } from '../../connection';
import { Role, User } from '../../entity';
import {
Expand All @@ -27,6 +27,10 @@ export class DefaultRolePermissionResolverStrategy implements RolePermissionReso
roleIds.length === 0
? []
: await this.connection.getRepository(ctx, Role).findBy(roleIds.map(id => ({ id })));
for (const roleId of roleIds) {
const foundRole = roles.find(role => role.id === roleId);
if (!foundRole) throw new EntityNotFoundError('Role', roleId);
}
// Copy so as to not mutate the original user object when setting roles
const userCopy = new User({ ...user, roles });
await this.connection.getRepository(ctx, User).save(userCopy, { reload: false });
Expand Down

0 comments on commit 9fb95b9

Please sign in to comment.