diff --git a/src/api/private/me/history/history.controller.ts b/src/api/private/me/history/history.controller.ts index 53960f0cf..dd37ad784 100644 --- a/src/api/private/me/history/history.controller.ts +++ b/src/api/private/me/history/history.controller.ts @@ -22,6 +22,8 @@ import { HistoryEntryUpdateDto } from '../../../../history/history-entry-update. import { HistoryEntryDto } from '../../../../history/history-entry.dto'; import { HistoryService } from '../../../../history/history.service'; import { ConsoleLoggerService } from '../../../../logger/console-logger.service'; +import { GetNotePipe } from '../../../../notes/get-note.pipe'; +import { Note } from '../../../../notes/note.entity'; import { UsersService } from '../../../../users/users.service'; @ApiTags('history') @@ -84,14 +86,14 @@ export class HistoryController { @Put(':note') async updateHistoryEntry( - @Param('note') noteId: string, + @Param('note', GetNotePipe) note: Note, @Body() entryUpdateDto: HistoryEntryUpdateDto, ): Promise { try { // ToDo: use actual user here const user = await this.userService.getUserByUsername('hardcoded'); const newEntry = await this.historyService.updateHistoryEntry( - noteId, + note, user, entryUpdateDto, ); diff --git a/src/api/public/me/me.controller.ts b/src/api/public/me/me.controller.ts index 3c9770a8a..718d26df7 100644 --- a/src/api/public/me/me.controller.ts +++ b/src/api/public/me/me.controller.ts @@ -31,7 +31,9 @@ import { HistoryService } from '../../../history/history.service'; import { ConsoleLoggerService } from '../../../logger/console-logger.service'; import { MediaUploadDto } from '../../../media/media-upload.dto'; import { MediaService } from '../../../media/media.service'; +import { GetNotePipe } from '../../../notes/get-note.pipe'; import { NoteMetadataDto } from '../../../notes/note-metadata.dto'; +import { Note } from '../../../notes/note.entity'; import { NotesService } from '../../../notes/notes.service'; import { UserInfoDto } from '../../../users/user-info.dto'; import { User } from '../../../users/user.entity'; @@ -119,7 +121,7 @@ export class MeController { @ApiNotFoundResponse({ description: notFoundDescription }) async updateHistoryEntry( @RequestUser() user: User, - @Param('note') note: string, + @Param('note', GetNotePipe) note: Note, @Body() entryUpdateDto: HistoryEntryUpdateDto, ): Promise { // ToDo: Check if user is allowed to pin this history entry diff --git a/src/history/history.service.spec.ts b/src/history/history.service.spec.ts index b98361f51..d66456946 100644 --- a/src/history/history.service.spec.ts +++ b/src/history/history.service.spec.ts @@ -218,7 +218,7 @@ describe('HistoryService', () => { async (entry: HistoryEntry): Promise => entry, ); const updatedHistoryEntry = await service.updateHistoryEntry( - alias, + note, user, { pinStatus: true, @@ -237,7 +237,7 @@ describe('HistoryService', () => { jest.spyOn(historyRepo, 'findOne').mockResolvedValueOnce(undefined); jest.spyOn(noteRepo, 'findOne').mockResolvedValueOnce(note); await expect( - service.updateHistoryEntry(alias, user, { + service.updateHistoryEntry(note, user, { pinStatus: true, }), ).rejects.toThrow(NotInDBError); diff --git a/src/history/history.service.ts b/src/history/history.service.ts index 4cb1302d7..5c1794c14 100644 --- a/src/history/history.service.ts +++ b/src/history/history.service.ts @@ -112,17 +112,17 @@ export class HistoryService { /** * @async * Update a history entry identified by the user and a note id or alias - * @param {string} noteIdOrAlias - the note that the history entry belongs to + * @param {Note} note - the note that the history entry belongs to * @param {User} user - the user that the history entry belongs to * @param {HistoryEntryUpdateDto} updateDto - the change that should be applied to the history entry * @return {HistoryEntry} the requested history entry */ async updateHistoryEntry( - noteIdOrAlias: string, + note: Note, user: User, updateDto: HistoryEntryUpdateDto, ): Promise { - const entry = await this.getEntryByNoteIdOrAlias(noteIdOrAlias, user); + const entry = await this.getEntryByNote(note, user); entry.pinStatus = updateDto.pinStatus; return await this.historyEntryRepository.save(entry); }