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:
parent
4b3c726101
commit
dbf467fea5
1 changed files with 20 additions and 13 deletions
|
@ -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;
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue