diff --git a/src/api/public/notes/notes.controller.ts b/src/api/public/notes/notes.controller.ts index 4bca6da81..923cf6354 100644 --- a/src/api/public/notes/notes.controller.ts +++ b/src/api/public/notes/notes.controller.ts @@ -164,7 +164,7 @@ export class NotesController { if (!this.permissionsService.mayRead(req.user, note)) { throw new UnauthorizedException('Reading note denied!'); } - return await this.noteService.getNoteContent(noteIdOrAlias); + return await this.noteService.getNoteContentByNote(note); } catch (e) { if (e instanceof NotInDBError) { throw new NotFoundException(e.message); diff --git a/src/notes/notes.service.ts b/src/notes/notes.service.ts index 107403e82..02a895f7b 100644 --- a/src/notes/notes.service.ts +++ b/src/notes/notes.service.ts @@ -74,10 +74,19 @@ export class NotesService { newNote.historyEntries = [HistoryEntry.create(owner)]; newNote.owner = owner; } - return this.noteRepository.save(newNote); + try { + return await this.noteRepository.save(newNote); + } catch { + this.logger.debug( + `A note with the alias '${alias}' already exists.`, + 'createNote', + ); + throw new AlreadyInDBError( + `A note with the alias '${alias}' already exists.`, + ); + } } - - async getCurrentContent(note: Note): Promise { + async getNoteContentByNote(note: Note): Promise { return (await this.getLatestRevision(note)).content; } diff --git a/test/public-api/notes.e2e-spec.ts b/test/public-api/notes.e2e-spec.ts index 8c2b71c71..dda8ef9da 100644 --- a/test/public-api/notes.e2e-spec.ts +++ b/test/public-api/notes.e2e-spec.ts @@ -74,7 +74,7 @@ describe('Notes', () => { .expect(201); expect(response.body.metadata?.id).toBeDefined(); expect( - await notesService.getCurrentContent( + await notesService.getNoteContentByNote( await notesService.getNoteByIdOrAlias(response.body.metadata.id), ), ).toEqual(content); @@ -109,7 +109,7 @@ describe('Notes', () => { .expect(201); expect(response.body.metadata?.id).toBeDefined(); return expect( - await notesService.getCurrentContent( + await notesService.getNoteContentByNote( await notesService.getNoteByIdOrAlias(response.body.metadata?.id), ), ).toEqual(content); @@ -141,7 +141,7 @@ describe('Notes', () => { .send(changedContent) .expect(200); await expect( - await notesService.getCurrentContent( + await notesService.getNoteContentByNote( await notesService.getNoteByIdOrAlias('test4'), ), ).toEqual(changedContent);