From 3396d3e47d3b9d55f774a9b4d7256437404a1878 Mon Sep 17 00:00:00 2001 From: David Mehren Date: Sun, 29 Aug 2021 21:19:53 +0200 Subject: [PATCH] UserService: Improve method naming This renames `createOrUpdateHistoryEntry` to `updateHistoryEntryTimestamp`, which reduces confusion with the similarly named `updateHistoryEntry` function. Signed-off-by: David Mehren --- src/api/private/notes/notes.controller.ts | 2 +- src/api/public/notes/notes.controller.ts | 3 +-- src/history/history.service.spec.ts | 6 +++--- src/history/history.service.ts | 5 +++-- test/private-api/history.e2e-spec.ts | 8 ++++---- test/public-api/me.e2e-spec.ts | 8 ++++---- 6 files changed, 16 insertions(+), 16 deletions(-) diff --git a/src/api/private/notes/notes.controller.ts b/src/api/private/notes/notes.controller.ts index 056c7c304..634712794 100644 --- a/src/api/private/notes/notes.controller.ts +++ b/src/api/private/notes/notes.controller.ts @@ -60,7 +60,7 @@ export class NotesController { if (!this.permissionsService.mayRead(user, note)) { throw new UnauthorizedException('Reading note denied!'); } - await this.historyService.createOrUpdateHistoryEntry(note, user); + await this.historyService.updateHistoryEntryTimestamp(note, user); return await this.noteService.toNoteDto(note); } diff --git a/src/api/public/notes/notes.controller.ts b/src/api/public/notes/notes.controller.ts index ecb2c65b7..97691b8d2 100644 --- a/src/api/public/notes/notes.controller.ts +++ b/src/api/public/notes/notes.controller.ts @@ -34,7 +34,6 @@ import { AlreadyInDBError, ForbiddenIdError, NotInDBError, - PermissionsUpdateInconsistentError, } from '../../../errors/errors'; import { HistoryService } from '../../../history/history.service'; import { ConsoleLoggerService } from '../../../logger/console-logger.service'; @@ -112,7 +111,7 @@ export class NotesController { if (!this.permissionsService.mayRead(user, note)) { throw new UnauthorizedException('Reading note denied!'); } - await this.historyService.createOrUpdateHistoryEntry(note, user); + await this.historyService.updateHistoryEntryTimestamp(note, user); return await this.noteService.toNoteDto(note); } diff --git a/src/history/history.service.spec.ts b/src/history/history.service.spec.ts index 955eec642..b98361f51 100644 --- a/src/history/history.service.spec.ts +++ b/src/history/history.service.spec.ts @@ -159,7 +159,7 @@ describe('HistoryService', () => { }); }); - describe('createOrUpdateHistoryEntry', () => { + describe('updateHistoryEntryTimestamp', () => { describe('works', () => { const user = {} as User; const alias = 'alias'; @@ -171,7 +171,7 @@ describe('HistoryService', () => { .mockImplementation( async (entry: HistoryEntry): Promise => entry, ); - const createHistoryEntry = await service.createOrUpdateHistoryEntry( + const createHistoryEntry = await service.updateHistoryEntryTimestamp( Note.create(user, alias), user, ); @@ -188,7 +188,7 @@ describe('HistoryService', () => { .mockImplementation( async (entry: HistoryEntry): Promise => entry, ); - const createHistoryEntry = await service.createOrUpdateHistoryEntry( + const createHistoryEntry = await service.updateHistoryEntryTimestamp( Note.create(user, alias), user, ); diff --git a/src/history/history.service.ts b/src/history/history.service.ts index 13a290ad5..4cb1302d7 100644 --- a/src/history/history.service.ts +++ b/src/history/history.service.ts @@ -86,12 +86,13 @@ export class HistoryService { /** * @async - * Create or update a history entry by the user and note. If the entry is merely updated the updatedAt date is set to the current date. + * Updates the updatedAt timestamp of a HistoryEntry. + * If no history entry exists, it will be created. * @param {Note} note - the note that the history entry belongs to * @param {User} user - the user that the history entry belongs to * @return {HistoryEntry} the requested history entry */ - async createOrUpdateHistoryEntry( + async updateHistoryEntryTimestamp( note: Note, user: User, ): Promise { diff --git a/test/private-api/history.e2e-spec.ts b/test/private-api/history.e2e-spec.ts index ea548c42c..d098c7bd1 100644 --- a/test/private-api/history.e2e-spec.ts +++ b/test/private-api/history.e2e-spec.ts @@ -87,7 +87,7 @@ describe('History', () => { .expect('Content-Type', /json/) .expect(200); expect(emptyResponse.body.length).toEqual(0); - const entry = await historyService.createOrUpdateHistoryEntry(note, user); + const entry = await historyService.updateHistoryEntryTimestamp(note, user); const entryDto = historyService.toHistoryEntryDto(entry); const response = await request(app.getHttpServer()) .get('/me/history') @@ -182,7 +182,7 @@ describe('History', () => { }); it('PUT /me/history/:note', async () => { - const entry = await historyService.createOrUpdateHistoryEntry(note2, user); + const entry = await historyService.updateHistoryEntryTimestamp(note2, user); expect(entry.pinStatus).toBeFalsy(); await request(app.getHttpServer()) .put(`/me/history/${entry.note.alias || 'undefined'}`) @@ -195,8 +195,8 @@ describe('History', () => { }); it('DELETE /me/history/:note', async () => { - const entry = await historyService.createOrUpdateHistoryEntry(note2, user); - const entry2 = await historyService.createOrUpdateHistoryEntry(note, user); + const entry = await historyService.updateHistoryEntryTimestamp(note2, user); + const entry2 = await historyService.updateHistoryEntryTimestamp(note, user); const entryDto = historyService.toHistoryEntryDto(entry2); await request(app.getHttpServer()) .delete(`/me/history/${entry.note.alias || 'undefined'}`) diff --git a/test/public-api/me.e2e-spec.ts b/test/public-api/me.e2e-spec.ts index 38ed4c5f5..17edd7d6e 100644 --- a/test/public-api/me.e2e-spec.ts +++ b/test/public-api/me.e2e-spec.ts @@ -96,7 +96,7 @@ describe('Me', () => { it(`GET /me/history`, async () => { const noteName = 'testGetNoteHistory1'; const note = await notesService.createNote('', noteName); - const createdHistoryEntry = await historyService.createOrUpdateHistoryEntry( + const createdHistoryEntry = await historyService.updateHistoryEntryTimestamp( note, user, ); @@ -123,7 +123,7 @@ describe('Me', () => { const noteName = 'testGetNoteHistory2'; const note = await notesService.createNote('', noteName); const createdHistoryEntry = - await historyService.createOrUpdateHistoryEntry(note, user); + await historyService.updateHistoryEntryTimestamp(note, user); const response = await request(app.getHttpServer()) .get(`/me/history/${noteName}`) .expect('Content-Type', /json/) @@ -151,7 +151,7 @@ describe('Me', () => { it('works', async () => { const noteName = 'testGetNoteHistory3'; const note = await notesService.createNote('', noteName); - await historyService.createOrUpdateHistoryEntry(note, user); + await historyService.updateHistoryEntryTimestamp(note, user); const historyEntryUpdateDto = new HistoryEntryUpdateDto(); historyEntryUpdateDto.pinStatus = true; const response = await request(app.getHttpServer()) @@ -181,7 +181,7 @@ describe('Me', () => { it('works', async () => { const noteName = 'testGetNoteHistory4'; const note = await notesService.createNote('', noteName); - await historyService.createOrUpdateHistoryEntry(note, user); + await historyService.updateHistoryEntryTimestamp(note, user); const response = await request(app.getHttpServer()) .delete(`/me/history/${noteName}`) .expect(204);