1
0
Fork 0
mirror of https://github.com/hedgedoc/hedgedoc.git synced 2025-04-11 18:13:05 +00:00

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,18 +26,25 @@ export class GetNotePipe implements PipeTransform<string, Promise<Note>> {
}
async transform(noteIdOrAlias: string, _: ArgumentMetadata): Promise<Note> {
let note: Note;
try {
note = await this.noteService.getNoteByIdOrAlias(noteIdOrAlias);
} catch (e) {
if (e instanceof NotInDBError) {
throw new NotFoundException(e.message);
}
if (e instanceof ForbiddenIdError) {
throw new BadRequestException(e.message);
}
throw e;
}
return note;
return await getNote(this.noteService, noteIdOrAlias);
}
}
export async function getNote(
noteService: NotesService,
noteIdOrAlias: string,
): Promise<Note> {
let note: Note;
try {
note = await noteService.getNoteByIdOrAlias(noteIdOrAlias);
} catch (e) {
if (e instanceof NotInDBError) {
throw new NotFoundException(e.message);
}
if (e instanceof ForbiddenIdError) {
throw new BadRequestException(e.message);
}
throw e;
}
return note;
}