mirror of
https://github.com/hedgedoc/hedgedoc.git
synced 2025-05-23 19:47:03 -04:00
refactor: remove cycling dependency between notes and revisions
Signed-off-by: Tilman Vatteroth <git@tilmanvatteroth.de>
This commit is contained in:
parent
8cdc90bb8e
commit
8596bed729
7 changed files with 10 additions and 66 deletions
|
@ -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,
|
||||
|
|
|
@ -359,38 +359,6 @@ describe('NotesService', () => {
|
|||
});
|
||||
});
|
||||
|
||||
describe('getLatestRevision', () => {
|
||||
it('works', async () => {
|
||||
const content = 'testContent';
|
||||
jest
|
||||
.spyOn(noteRepo, 'save')
|
||||
.mockImplementation(async (note: Note): Promise<Note> => 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> => 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;
|
||||
|
|
|
@ -39,7 +39,6 @@ export class NotesService {
|
|||
@InjectRepository(User) private userRepository: Repository<User>,
|
||||
@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<string> {
|
||||
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<Revision> {
|
||||
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<Revision> {
|
||||
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<User | null> {
|
||||
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,
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue