chore: extract getNote code from GetNotePipe.transform

This was done so the same code could be used in the PermissionsGuard

Signed-off-by: Philip Molares <philip.molares@udo.edu>
This commit is contained in:
Philip Molares 2021-11-21 17:12:35 +01:00
parent 4b3c726101
commit dbf467fea5

View file

@ -26,9 +26,17 @@ export class GetNotePipe implements PipeTransform<string, Promise<Note>> {
}
async transform(noteIdOrAlias: string, _: ArgumentMetadata): Promise<Note> {
return await getNote(this.noteService, noteIdOrAlias);
}
}
export async function getNote(
noteService: NotesService,
noteIdOrAlias: string,
): Promise<Note> {
let note: Note;
try {
note = await this.noteService.getNoteByIdOrAlias(noteIdOrAlias);
note = await noteService.getNoteByIdOrAlias(noteIdOrAlias);
} catch (e) {
if (e instanceof NotInDBError) {
throw new NotFoundException(e.message);
@ -40,4 +48,3 @@ export class GetNotePipe implements PipeTransform<string, Promise<Note>> {
}
return note;
}
}