mirror of
https://github.com/hedgedoc/hedgedoc.git
synced 2025-05-19 09:45:37 -04: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> {
|
async transform(noteIdOrAlias: string, _: ArgumentMetadata): Promise<Note> {
|
||||||
let note: Note;
|
return await getNote(this.noteService, noteIdOrAlias);
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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
Add a link
Reference in a new issue