From 772263317dec9e8a1669fde92a359dd00e45e62e Mon Sep 17 00:00:00 2001 From: David Mehren Date: Thu, 29 Apr 2021 18:30:17 +0200 Subject: [PATCH] NotesService: Fix type errors Signed-off-by: David Mehren --- src/notes/notes.service.ts | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/src/notes/notes.service.ts b/src/notes/notes.service.ts index 05e82ce7d..865d6978f 100644 --- a/src/notes/notes.service.ts +++ b/src/notes/notes.service.ts @@ -102,14 +102,18 @@ export class NotesService { } 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.`, - ); + } catch (e) { + if (alias) { + this.logger.debug( + `A note with the alias '${alias}' already exists.`, + 'createNote', + ); + throw new AlreadyInDBError( + `A note with the alias '${alias}' already exists.`, + ); + } else { + throw e; + } } } @@ -304,7 +308,7 @@ export class NotesService { * @param {Note} note - the note to use * @return {User} user to be used as updateUser in the NoteDto */ - async calculateUpdateUser(note: Note): Promise { + async calculateUpdateUser(note: Note): Promise { const lastRevision = await this.getLatestRevision(note); if (lastRevision && lastRevision.authorships) { // Sort the last Revisions Authorships by their updatedAt Date to get the latest one @@ -333,7 +337,7 @@ export class NotesService { */ toNotePermissionsDto(note: Note): NotePermissionsDto { return { - owner: this.usersService.toUserDto(note.owner), + owner: note.owner ? this.usersService.toUserDto(note.owner) : undefined, sharedToUsers: note.userPermissions.map((noteUserPermission) => ({ user: this.usersService.toUserDto(noteUserPermission.user), canEdit: noteUserPermission.canEdit,