NotesService: Fix type errors

Signed-off-by: David Mehren <git@herrmehren.de>
This commit is contained in:
David Mehren 2021-04-29 18:30:17 +02:00
parent 3b0ffaca30
commit f8efb9717e
No known key found for this signature in database
GPG key ID: 185982BA4C42B7C3

View file

@ -102,14 +102,18 @@ export class NotesService {
} }
try { try {
return await this.noteRepository.save(newNote); return await this.noteRepository.save(newNote);
} catch { } catch (e) {
this.logger.debug( if (alias) {
`A note with the alias '${alias}' already exists.`, this.logger.debug(
'createNote', `A note with the alias '${alias}' already exists.`,
); 'createNote',
throw new AlreadyInDBError( );
`A note with the alias '${alias}' already exists.`, 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 * @param {Note} note - the note to use
* @return {User} user to be used as updateUser in the NoteDto * @return {User} user to be used as updateUser in the NoteDto
*/ */
async calculateUpdateUser(note: Note): Promise<User> { async calculateUpdateUser(note: Note): Promise<User | null> {
const lastRevision = await this.getLatestRevision(note); const lastRevision = await this.getLatestRevision(note);
if (lastRevision && lastRevision.authorships) { if (lastRevision && lastRevision.authorships) {
// Sort the last Revisions Authorships by their updatedAt Date to get the latest one // 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 { toNotePermissionsDto(note: Note): NotePermissionsDto {
return { return {
owner: this.usersService.toUserDto(note.owner), owner: note.owner ? this.usersService.toUserDto(note.owner) : undefined,
sharedToUsers: note.userPermissions.map((noteUserPermission) => ({ sharedToUsers: note.userPermissions.map((noteUserPermission) => ({
user: this.usersService.toUserDto(noteUserPermission.user), user: this.usersService.toUserDto(noteUserPermission.user),
canEdit: noteUserPermission.canEdit, canEdit: noteUserPermission.canEdit,