mirror of
https://github.com/hedgedoc/hedgedoc.git
synced 2025-02-23 11:01:19 +00:00
HistoryService: Refactor deleteHistoryEntry
The function now expects a `Note` object instead of a noteId to make it more consistent with other functions. Signed-off-by: David Mehren <git@herrmehren.de>
This commit is contained in:
parent
839877dbc5
commit
d2b60a316f
6 changed files with 13 additions and 13 deletions
|
@ -107,11 +107,13 @@ export class HistoryController {
|
|||
}
|
||||
|
||||
@Delete(':note')
|
||||
async deleteHistoryEntry(@Param('note') noteId: string): Promise<void> {
|
||||
async deleteHistoryEntry(
|
||||
@Param('note', GetNotePipe) note: Note,
|
||||
): Promise<void> {
|
||||
try {
|
||||
// ToDo: use actual user here
|
||||
const user = await this.userService.getUserByUsername('hardcoded');
|
||||
await this.historyService.deleteHistoryEntry(noteId, user);
|
||||
await this.historyService.deleteHistoryEntry(note, user);
|
||||
} catch (e) {
|
||||
if (e instanceof NotInDBError) {
|
||||
throw new NotFoundException(e.message);
|
||||
|
|
|
@ -149,7 +149,7 @@ export class MeController {
|
|||
@ApiNotFoundResponse({ description: notFoundDescription })
|
||||
async deleteHistoryEntry(
|
||||
@RequestUser() user: User,
|
||||
@Param('note') note: string,
|
||||
@Param('note', GetNotePipe) note: Note,
|
||||
): Promise<void> {
|
||||
// ToDo: Check if user is allowed to delete note
|
||||
try {
|
||||
|
|
|
@ -311,7 +311,7 @@ describe('HistoryService', () => {
|
|||
return entry;
|
||||
},
|
||||
);
|
||||
await service.deleteHistoryEntry(alias, user);
|
||||
await service.deleteHistoryEntry(note, user);
|
||||
});
|
||||
});
|
||||
describe('fails', () => {
|
||||
|
@ -321,7 +321,7 @@ describe('HistoryService', () => {
|
|||
const note = Note.create(user, alias);
|
||||
jest.spyOn(historyRepo, 'findOne').mockResolvedValueOnce(undefined);
|
||||
jest.spyOn(noteRepo, 'findOne').mockResolvedValueOnce(note);
|
||||
await expect(service.deleteHistoryEntry(alias, user)).rejects.toThrow(
|
||||
await expect(service.deleteHistoryEntry(note, user)).rejects.toThrow(
|
||||
NotInDBError,
|
||||
);
|
||||
});
|
||||
|
|
|
@ -130,12 +130,12 @@ export class HistoryService {
|
|||
/**
|
||||
* @async
|
||||
* Delete the 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
|
||||
* @throws {NotInDBError} the specified history entry does not exist
|
||||
*/
|
||||
async deleteHistoryEntry(noteIdOrAlias: string, user: User): Promise<void> {
|
||||
const entry = await this.getEntryByNoteIdOrAlias(noteIdOrAlias, user);
|
||||
async deleteHistoryEntry(note: Note, user: User): Promise<void> {
|
||||
const entry = await this.getEntryByNote(note, user);
|
||||
await this.historyEntryRepository.remove(entry);
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -191,7 +191,7 @@ describe('History', () => {
|
|||
const userEntries = await historyService.getEntriesByUser(user);
|
||||
expect(userEntries.length).toEqual(1);
|
||||
expect(userEntries[0].pinStatus).toBeTruthy();
|
||||
await historyService.deleteHistoryEntry(note2.alias, user);
|
||||
await historyService.deleteHistoryEntry(note2, user);
|
||||
});
|
||||
|
||||
it('DELETE /me/history/:note', async () => {
|
||||
|
|
|
@ -96,10 +96,8 @@ describe('Me', () => {
|
|||
it(`GET /me/history`, async () => {
|
||||
const noteName = 'testGetNoteHistory1';
|
||||
const note = await notesService.createNote('', noteName);
|
||||
const createdHistoryEntry = await historyService.updateHistoryEntryTimestamp(
|
||||
note,
|
||||
user,
|
||||
);
|
||||
const createdHistoryEntry =
|
||||
await historyService.updateHistoryEntryTimestamp(note, user);
|
||||
const response = await request(app.getHttpServer())
|
||||
.get('/me/history')
|
||||
.expect('Content-Type', /json/)
|
||||
|
|
Loading…
Reference in a new issue