mirror of
https://github.com/hedgedoc/hedgedoc.git
synced 2024-11-28 22:14:04 -05:00
refactor(identity): lazy-load relations
Signed-off-by: David Mehren <git@herrmehren.de>
This commit is contained in:
parent
3539216cf3
commit
dcfb00adc1
2 changed files with 4 additions and 4 deletions
|
@ -32,7 +32,7 @@ export class Identity {
|
||||||
@ManyToOne((_) => User, (user) => user.identities, {
|
@ManyToOne((_) => User, (user) => user.identities, {
|
||||||
onDelete: 'CASCADE', // This deletes the Identity, when the associated User is deleted
|
onDelete: 'CASCADE', // This deletes the Identity, when the associated User is deleted
|
||||||
})
|
})
|
||||||
user: User;
|
user: Promise<User>;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The ProviderType of the identity
|
* The ProviderType of the identity
|
||||||
|
@ -103,7 +103,7 @@ export class Identity {
|
||||||
syncSource: boolean,
|
syncSource: boolean,
|
||||||
): Omit<Identity, 'id' | 'createdAt' | 'updatedAt'> {
|
): Omit<Identity, 'id' | 'createdAt' | 'updatedAt'> {
|
||||||
const newIdentity = new Identity();
|
const newIdentity = new Identity();
|
||||||
newIdentity.user = user;
|
newIdentity.user = Promise.resolve(user);
|
||||||
newIdentity.providerType = providerType;
|
newIdentity.providerType = providerType;
|
||||||
newIdentity.providerName = null;
|
newIdentity.providerName = null;
|
||||||
newIdentity.syncSource = syncSource;
|
newIdentity.syncSource = syncSource;
|
||||||
|
|
|
@ -60,7 +60,7 @@ describe('IdentityService', () => {
|
||||||
await checkPassword(password, identity.passwordHash ?? '').then(
|
await checkPassword(password, identity.passwordHash ?? '').then(
|
||||||
(result) => expect(result).toBeTruthy(),
|
(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(
|
await checkPassword(newPassword, identity.passwordHash ?? '').then(
|
||||||
(result) => expect(result).toBeTruthy(),
|
(result) => expect(result).toBeTruthy(),
|
||||||
);
|
);
|
||||||
expect(identity.user).toEqual(user);
|
expect(await identity.user).toEqual(user);
|
||||||
});
|
});
|
||||||
it('fails, when user has no local identity', async () => {
|
it('fails, when user has no local identity', async () => {
|
||||||
user.identities = Promise.resolve([]);
|
user.identities = Promise.resolve([]);
|
||||||
|
|
Loading…
Reference in a new issue