diff --git a/src/notes/notes.module.ts b/src/notes/notes.module.ts index 1e83c85ab..0647e0475 100644 --- a/src/notes/notes.module.ts +++ b/src/notes/notes.module.ts @@ -3,7 +3,7 @@ * * SPDX-License-Identifier: AGPL-3.0-only */ -import { forwardRef, Module } from '@nestjs/common'; +import { Module } from '@nestjs/common'; import { ConfigModule } from '@nestjs/config'; import { TypeOrmModule } from '@nestjs/typeorm'; @@ -30,7 +30,7 @@ import { Tag } from './tag.entity'; User, Alias, ]), - forwardRef(() => RevisionsModule), + RevisionsModule, UsersModule, GroupsModule, LoggerModule, diff --git a/src/notes/notes.service.spec.ts b/src/notes/notes.service.spec.ts index 833c97b23..2e984bd1f 100644 --- a/src/notes/notes.service.spec.ts +++ b/src/notes/notes.service.spec.ts @@ -359,38 +359,6 @@ describe('NotesService', () => { }); }); - describe('getLatestRevision', () => { - it('works', async () => { - const content = 'testContent'; - jest - .spyOn(noteRepo, 'save') - .mockImplementation(async (note: Note): Promise => note); - const newNote = await service.createNote(content, null); - const revisions = await newNote.revisions; - jest.spyOn(revisionRepo, 'findOne').mockResolvedValueOnce(revisions[0]); - await service.getLatestRevision(newNote).then((result) => { - expect(result).toEqual(revisions[0]); - }); - }); - }); - - describe('getFirstRevision', () => { - it('works', async () => { - const user = {} as User; - user.username = 'hardcoded'; - const content = 'testContent'; - jest - .spyOn(noteRepo, 'save') - .mockImplementation(async (note: Note): Promise => note); - const newNote = await service.createNote(content, null); - const revisions = await newNote.revisions; - jest.spyOn(revisionRepo, 'findOne').mockResolvedValueOnce(revisions[0]); - await service.getLatestRevision(newNote).then((result) => { - expect(result).toEqual(revisions[0]); - }); - }); - }); - describe('getNoteByIdOrAlias', () => { it('works', async () => { const user = User.create('hardcoded', 'Testy') as User; diff --git a/src/notes/notes.service.ts b/src/notes/notes.service.ts index f3d81e006..fa6b5a085 100644 --- a/src/notes/notes.service.ts +++ b/src/notes/notes.service.ts @@ -39,7 +39,6 @@ export class NotesService { @InjectRepository(User) private userRepository: Repository, @Inject(UsersService) private usersService: UsersService, @Inject(GroupsService) private groupsService: GroupsService, - @Inject(forwardRef(() => RevisionsService)) private revisionsService: RevisionsService, @Inject(noteConfiguration.KEY) private noteConfig: NoteConfig, @@ -117,27 +116,7 @@ export class NotesService { * @return {string} the content of the note */ async getNoteContent(note: Note): Promise { - return (await this.getLatestRevision(note)).content; - } - - /** - * @async - * Get the first revision of the note. - * @param {Note} note - the note to use - * @return {Revision} the first revision of the note - */ - async getLatestRevision(note: Note): Promise { - return await this.revisionsService.getLatestRevision(note); - } - - /** - * @async - * Get the last revision of the note. - * @param {Note} note - the note to use - * @return {Revision} the last revision of the note - */ - async getFirstRevision(note: Note): Promise { - return await this.revisionsService.getFirstRevision(note); + return (await this.revisionsService.getLatestRevision(note)).content; } /** @@ -264,7 +243,7 @@ export class NotesService { * @return {User} user to be used as updateUser in the NoteDto */ async calculateUpdateUser(note: Note): Promise { - const lastRevision = await this.getLatestRevision(note); + const lastRevision = await this.revisionsService.getLatestRevision(note); const edits = await lastRevision.edits; if (edits.length > 0) { // Sort the last Revisions Edits by their updatedAt Date to get the latest one @@ -333,7 +312,8 @@ export class NotesService { permissions: await this.toNotePermissionsDto(note), tags: await this.toTagList(note), version: note.version, - updatedAt: (await this.getLatestRevision(note)).createdAt, + updatedAt: (await this.revisionsService.getLatestRevision(note)) + .createdAt, updateUsername: updateUser ? updateUser.username : null, viewCount: note.viewCount, }; diff --git a/src/revisions/revisions.module.ts b/src/revisions/revisions.module.ts index 06ebd7c41..453339c6b 100644 --- a/src/revisions/revisions.module.ts +++ b/src/revisions/revisions.module.ts @@ -3,13 +3,12 @@ * * SPDX-License-Identifier: AGPL-3.0-only */ -import { forwardRef, Module } from '@nestjs/common'; +import { Module } from '@nestjs/common'; import { ConfigModule } from '@nestjs/config'; import { TypeOrmModule } from '@nestjs/typeorm'; import { AuthorsModule } from '../authors/authors.module'; import { LoggerModule } from '../logger/logger.module'; -import { NotesModule } from '../notes/notes.module'; import { Edit } from './edit.entity'; import { EditService } from './edit.service'; import { Revision } from './revision.entity'; @@ -18,7 +17,6 @@ import { RevisionsService } from './revisions.service'; @Module({ imports: [ TypeOrmModule.forFeature([Revision, Edit]), - forwardRef(() => NotesModule), LoggerModule, ConfigModule, AuthorsModule, diff --git a/src/revisions/revisions.service.ts b/src/revisions/revisions.service.ts index a2ae121c8..577c558b3 100644 --- a/src/revisions/revisions.service.ts +++ b/src/revisions/revisions.service.ts @@ -3,14 +3,13 @@ * * SPDX-License-Identifier: AGPL-3.0-only */ -import { forwardRef, Inject, Injectable } from '@nestjs/common'; +import { Injectable } from '@nestjs/common'; import { InjectRepository } from '@nestjs/typeorm'; import { Equal, Repository } from 'typeorm'; import { NotInDBError } from '../errors/errors'; import { ConsoleLoggerService } from '../logger/console-logger.service'; import { Note } from '../notes/note.entity'; -import { NotesService } from '../notes/notes.service'; import { EditService } from './edit.service'; import { RevisionMetadataDto } from './revision-metadata.dto'; import { RevisionDto } from './revision.dto'; @@ -27,7 +26,6 @@ export class RevisionsService { private readonly logger: ConsoleLoggerService, @InjectRepository(Revision) private revisionRepository: Repository, - @Inject(forwardRef(() => NotesService)) private notesService: NotesService, private editService: EditService, ) { this.logger.setContext(RevisionsService.name); diff --git a/test/private-api/notes.e2e-spec.ts b/test/private-api/notes.e2e-spec.ts index 5536d25c2..b591ac3c0 100644 --- a/test/private-api/notes.e2e-spec.ts +++ b/test/private-api/notes.e2e-spec.ts @@ -269,7 +269,7 @@ describe('Notes', () => { user, 'test5', ); - const revision = await testSetup.notesService.getLatestRevision(note); + const revision = await testSetup.revisionsService.getLatestRevision(note); const response = await agent .get(`/api/private/notes/test5/revisions/${revision.id}`) .expect('Content-Type', /json/) diff --git a/test/public-api/notes.e2e-spec.ts b/test/public-api/notes.e2e-spec.ts index da70714d7..43877548a 100644 --- a/test/public-api/notes.e2e-spec.ts +++ b/test/public-api/notes.e2e-spec.ts @@ -361,7 +361,7 @@ describe('Notes', () => { 'test7', ); - const revision = await testSetup.notesService.getLatestRevision(note); + const revision = await testSetup.revisionsService.getLatestRevision(note); const response = await request(testSetup.app.getHttpServer()) .get(`/api/v2/notes/test7/revisions/${revision.id}`) .expect('Content-Type', /json/)