diff --git a/src/authors/author.entity.ts b/src/authors/author.entity.ts index bc24af958..de46461f1 100644 --- a/src/authors/author.entity.ts +++ b/src/authors/author.entity.ts @@ -39,21 +39,21 @@ export class Author { * Only contains sessions for anonymous users, which don't have a user set */ @OneToMany(() => Session, (session) => session.author) - sessions: Session[]; + sessions: Promise; /** * User that this author corresponds to * Only set when the user was identified (by a browser session) as a registered user at edit-time */ @ManyToOne(() => User, (user) => user.authors, { nullable: true }) - user: User | null; + user: Promise; /** * List of edits that this author created * All edits must belong to the same note */ @OneToMany(() => Edit, (edit) => edit.author) - edits: Edit[]; + edits: Promise; // eslint-disable-next-line @typescript-eslint/no-empty-function private constructor() {} @@ -61,9 +61,9 @@ export class Author { public static create(color: number): Omit { const newAuthor = new Author(); newAuthor.color = color; - newAuthor.sessions = []; - newAuthor.user = null; - newAuthor.edits = []; + newAuthor.sessions = Promise.resolve([]); + newAuthor.user = Promise.resolve(null); + newAuthor.edits = Promise.resolve([]); return newAuthor; } } diff --git a/src/notes/notes.service.spec.ts b/src/notes/notes.service.spec.ts index 3be7f998f..686646ecd 100644 --- a/src/notes/notes.service.spec.ts +++ b/src/notes/notes.service.spec.ts @@ -703,7 +703,7 @@ describe('NotesService', () => { it('works', async () => { const user = User.create('hardcoded', 'Testy') as User; const author = Author.create(1); - author.user = user; + author.user = Promise.resolve(user); const group = Group.create('testGroup', 'testGroup', false) as Group; const content = 'testContent'; jest @@ -798,7 +798,7 @@ describe('NotesService', () => { it('works', async () => { const user = User.create('hardcoded', 'Testy') as User; const author = Author.create(1); - author.user = user; + author.user = Promise.resolve(user); const otherUser = User.create('other hardcoded', 'Testy2') as User; otherUser.username = 'other hardcoded user'; const group = Group.create('testGroup', 'testGroup', false) as Group; diff --git a/src/notes/notes.service.ts b/src/notes/notes.service.ts index 87f799ed2..05f8d2efc 100644 --- a/src/notes/notes.service.ts +++ b/src/notes/notes.service.ts @@ -343,7 +343,7 @@ export class NotesService { if (lastRevision && lastRevision.edits) { // Sort the last Revisions Edits by their updatedAt Date to get the latest one // the user of that Edit is the updateUser - return lastRevision.edits.sort( + return await lastRevision.edits.sort( (a, b) => b.updatedAt.getTime() - a.updatedAt.getTime(), )[0].author.user; } diff --git a/src/seed.ts b/src/seed.ts index 0f89ce1f5..c280cacde 100644 --- a/src/seed.ts +++ b/src/seed.ts @@ -67,7 +67,7 @@ createConnection({ const identity = Identity.create(user, ProviderType.LOCAL, false); identity.passwordHash = await hashPassword(password); connection.manager.create(Identity, identity); - author.user = user; + author.user = Promise.resolve(user); const revision = Revision.create( 'This is a test note', 'This is a test note',