-
-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(core): Improved resolution of Administrator.user
Relates to #1489. The previous resolution method would fail when using a non-native auth strategy that was not based on an email identifier.
- Loading branch information
1 parent
daa4731
commit c2a4685
Showing
2 changed files
with
8 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 7 additions & 7 deletions
14
packages/core/src/api/resolvers/entity/administrator-entity.resolver.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,25 @@ | ||
import { Parent, ResolveField, Resolver } from '@nestjs/graphql'; | ||
|
||
import { EntityNotFoundError, InternalServerError } from '../../../common/error/errors'; | ||
import { TransactionalConnection } from '../../../connection/index'; | ||
import { Administrator } from '../../../entity/administrator/administrator.entity'; | ||
import { User } from '../../../entity/user/user.entity'; | ||
import { UserService } from '../../../service/services/user.service'; | ||
import { RequestContext } from '../../common/request-context'; | ||
import { Ctx } from '../../decorators/request-context.decorator'; | ||
|
||
@Resolver('Administrator') | ||
export class AdministratorEntityResolver { | ||
constructor(private userService: UserService) {} | ||
constructor(private connection: TransactionalConnection) {} | ||
|
||
@ResolveField() | ||
async user(@Ctx() ctx: RequestContext, @Parent() administrator: Administrator): Promise<User> { | ||
if (administrator.user) { | ||
return administrator.user; | ||
} | ||
const user = await this.userService.getUserByEmailAddress(ctx, administrator.emailAddress); | ||
if (!user) { | ||
throw new EntityNotFoundError('User', '<not found>'); | ||
} | ||
const { user } = await this.connection.getEntityOrThrow(ctx, Administrator, administrator.id, { | ||
relations: { | ||
user: { roles: true }, | ||
}, | ||
}); | ||
return user; | ||
} | ||
} |