refactor(identity): lazy-load relations

Signed-off-by: David Mehren <git@herrmehren.de>
This commit is contained in:
David Mehren 2021-12-05 22:10:59 +01:00
parent 977ed4b9fa
commit e21b5e695d
No known key found for this signature in database
GPG key ID: 185982BA4C42B7C3
2 changed files with 4 additions and 4 deletions

View file

@ -32,7 +32,7 @@ export class Identity {
@ManyToOne((_) => User, (user) => user.identities, {
onDelete: 'CASCADE', // This deletes the Identity, when the associated User is deleted
})
user: User;
user: Promise<User>;
/**
* The ProviderType of the identity
@ -103,7 +103,7 @@ export class Identity {
syncSource: boolean,
): Omit<Identity, 'id' | 'createdAt' | 'updatedAt'> {
const newIdentity = new Identity();
newIdentity.user = user;
newIdentity.user = Promise.resolve(user);
newIdentity.providerType = providerType;
newIdentity.providerName = null;
newIdentity.syncSource = syncSource;

View file

@ -60,7 +60,7 @@ describe('IdentityService', () => {
await checkPassword(password, identity.passwordHash ?? '').then(
(result) => expect(result).toBeTruthy(),
);
expect(identity.user).toEqual(user);
expect(await identity.user).toEqual(user);
});
});
@ -83,7 +83,7 @@ describe('IdentityService', () => {
await checkPassword(newPassword, identity.passwordHash ?? '').then(
(result) => expect(result).toBeTruthy(),
);
expect(identity.user).toEqual(user);
expect(await identity.user).toEqual(user);
});
it('fails, when user has no local identity', async () => {
user.identities = Promise.resolve([]);