From 279d90dad19f7a773b57262c7af8a5443bb10543 Mon Sep 17 00:00:00 2001 From: David Mehren Date: Sun, 29 Aug 2021 21:57:35 +0200 Subject: [PATCH] HistoryService: Remove `getEntryByNoteIdOrAlias` As we now have a GetNotePipe, we can easily get rid of this function. All clients can directly provide a `Note` instance and use `getEntryByNote`. Signed-off-by: David Mehren --- src/api/public/me/me.controller.ts | 7 ++----- src/history/history.service.spec.ts | 30 ----------------------------- src/history/history.service.ts | 18 +---------------- 3 files changed, 3 insertions(+), 52 deletions(-) diff --git a/src/api/public/me/me.controller.ts b/src/api/public/me/me.controller.ts index 26ae88fea..fd5bcff84 100644 --- a/src/api/public/me/me.controller.ts +++ b/src/api/public/me/me.controller.ts @@ -95,13 +95,10 @@ export class MeController { @ApiNotFoundResponse({ description: notFoundDescription }) async getHistoryEntry( @RequestUser() user: User, - @Param('note') note: string, + @Param('note', GetNotePipe) note: Note, ): Promise { try { - const foundEntry = await this.historyService.getEntryByNoteIdOrAlias( - note, - user, - ); + const foundEntry = await this.historyService.getEntryByNote(note, user); return this.historyService.toHistoryEntryDto(foundEntry); } catch (e) { if (e instanceof NotInDBError) { diff --git a/src/history/history.service.spec.ts b/src/history/history.service.spec.ts index 1aecaaec5..ddfa763cb 100644 --- a/src/history/history.service.spec.ts +++ b/src/history/history.service.spec.ts @@ -135,30 +135,6 @@ describe('HistoryService', () => { }); }); - describe('getEntryByNoteIdOrAlias', () => { - const user = {} as User; - const alias = 'alias'; - describe('works', () => { - it('with history entry', async () => { - const note = Note.create(user, alias); - const historyEntry = HistoryEntry.create(user, note); - jest.spyOn(historyRepo, 'findOne').mockResolvedValueOnce(historyEntry); - jest.spyOn(noteRepo, 'findOne').mockResolvedValueOnce(note); - expect(await service.getEntryByNoteIdOrAlias(alias, user)).toEqual( - historyEntry, - ); - }); - }); - describe('fails', () => { - it('with an non-existing note', async () => { - jest.spyOn(noteRepo, 'findOne').mockResolvedValueOnce(undefined); - await expect( - service.getEntryByNoteIdOrAlias(alias, {} as User), - ).rejects.toThrow(NotInDBError); - }); - }); - }); - describe('updateHistoryEntryTimestamp', () => { describe('works', () => { const user = {} as User; @@ -325,12 +301,6 @@ describe('HistoryService', () => { NotInDBError, ); }); - it('without a note', async () => { - jest.spyOn(noteRepo, 'findOne').mockResolvedValueOnce(undefined); - await expect( - service.getEntryByNoteIdOrAlias(alias, {} as User), - ).rejects.toThrow(NotInDBError); - }); }); }); diff --git a/src/history/history.service.ts b/src/history/history.service.ts index 1ae9debd6..f61b8e93b 100644 --- a/src/history/history.service.ts +++ b/src/history/history.service.ts @@ -45,22 +45,6 @@ export class HistoryService { }); } - /** - * @async - * Get a history entry by the user and note, which is specified via id or alias - * @param {string} noteIdOrAlias - the id or alias specifying the note - * @param {User} user - the user that the note belongs to - * @throws {NotInDBError} the specified note does not exist - * @return {HistoryEntry} the requested history entry - */ - async getEntryByNoteIdOrAlias( - noteIdOrAlias: string, - user: User, - ): Promise { - const note = await this.notesService.getNoteByIdOrAlias(noteIdOrAlias); - return await this.getEntryByNote(note, user); - } - /** * @async * Get a history entry by the user and note @@ -68,7 +52,7 @@ export class HistoryService { * @param {User} user - the user that the history entry belongs to * @return {HistoryEntry} the requested history entry */ - private async getEntryByNote(note: Note, user: User): Promise { + async getEntryByNote(note: Note, user: User): Promise { const entry = await this.historyEntryRepository.findOne({ where: { note: note,