mirror of
https://github.com/hedgedoc/hedgedoc.git
synced 2025-05-25 20:44:49 -04:00
chore: move get-note-pipe to api utils
Signed-off-by: Philip Molares <philip.molares@udo.edu>
This commit is contained in:
parent
9093e5fabc
commit
7927ac2217
5 changed files with 8 additions and 8 deletions
|
@ -24,9 +24,9 @@ import { HistoryEntryDto } from '../../../../history/history-entry.dto';
|
|||
import { HistoryService } from '../../../../history/history.service';
|
||||
import { SessionGuard } from '../../../../identity/session.guard';
|
||||
import { ConsoleLoggerService } from '../../../../logger/console-logger.service';
|
||||
import { GetNotePipe } from '../../../../notes/get-note.pipe';
|
||||
import { Note } from '../../../../notes/note.entity';
|
||||
import { User } from '../../../../users/user.entity';
|
||||
import { GetNotePipe } from '../../../utils/get-note.pipe';
|
||||
import { RequestUser } from '../../../utils/request-user.decorator';
|
||||
|
||||
@UseGuards(SessionGuard)
|
||||
|
|
|
@ -27,7 +27,6 @@ import { SessionGuard } from '../../../identity/session.guard';
|
|||
import { ConsoleLoggerService } from '../../../logger/console-logger.service';
|
||||
import { MediaUploadDto } from '../../../media/media-upload.dto';
|
||||
import { MediaService } from '../../../media/media.service';
|
||||
import { GetNotePipe } from '../../../notes/get-note.pipe';
|
||||
import { NoteDto } from '../../../notes/note.dto';
|
||||
import { Note } from '../../../notes/note.entity';
|
||||
import { NoteMediaDeletionDto } from '../../../notes/note.media-deletion.dto';
|
||||
|
@ -38,6 +37,7 @@ import { RevisionDto } from '../../../revisions/revision.dto';
|
|||
import { RevisionsService } from '../../../revisions/revisions.service';
|
||||
import { User } from '../../../users/user.entity';
|
||||
import { UsersService } from '../../../users/users.service';
|
||||
import { GetNotePipe } from '../../utils/get-note.pipe';
|
||||
import { MarkdownBody } from '../../utils/markdownbody-decorator';
|
||||
import { RequestUser } from '../../utils/request-user.decorator';
|
||||
|
||||
|
|
|
@ -31,7 +31,6 @@ import { HistoryService } from '../../../history/history.service';
|
|||
import { ConsoleLoggerService } from '../../../logger/console-logger.service';
|
||||
import { MediaUploadDto } from '../../../media/media-upload.dto';
|
||||
import { MediaService } from '../../../media/media.service';
|
||||
import { GetNotePipe } from '../../../notes/get-note.pipe';
|
||||
import { NoteMetadataDto } from '../../../notes/note-metadata.dto';
|
||||
import { Note } from '../../../notes/note.entity';
|
||||
import { NotesService } from '../../../notes/notes.service';
|
||||
|
@ -43,6 +42,7 @@ import {
|
|||
successfullyDeletedDescription,
|
||||
unauthorizedDescription,
|
||||
} from '../../utils/descriptions';
|
||||
import { GetNotePipe } from '../../utils/get-note.pipe';
|
||||
import { RequestUser } from '../../utils/request-user.decorator';
|
||||
|
||||
@ApiTags('me')
|
||||
|
|
|
@ -39,7 +39,6 @@ import { HistoryService } from '../../../history/history.service';
|
|||
import { ConsoleLoggerService } from '../../../logger/console-logger.service';
|
||||
import { MediaUploadDto } from '../../../media/media-upload.dto';
|
||||
import { MediaService } from '../../../media/media.service';
|
||||
import { GetNotePipe } from '../../../notes/get-note.pipe';
|
||||
import { NoteMetadataDto } from '../../../notes/note-metadata.dto';
|
||||
import {
|
||||
NotePermissionsDto,
|
||||
|
@ -60,6 +59,7 @@ import {
|
|||
unauthorizedDescription,
|
||||
} from '../../utils/descriptions';
|
||||
import { FullApi } from '../../utils/fullapi-decorator';
|
||||
import { GetNotePipe } from '../../utils/get-note.pipe';
|
||||
import { MarkdownBody } from '../../utils/markdownbody-decorator';
|
||||
import { RequestUser } from '../../utils/request-user.decorator';
|
||||
|
||||
|
|
43
src/api/utils/get-note.pipe.ts
Normal file
43
src/api/utils/get-note.pipe.ts
Normal file
|
@ -0,0 +1,43 @@
|
|||
/*
|
||||
* SPDX-FileCopyrightText: 2021 The HedgeDoc developers (see AUTHORS file)
|
||||
*
|
||||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
*/
|
||||
import {
|
||||
ArgumentMetadata,
|
||||
BadRequestException,
|
||||
Injectable,
|
||||
NotFoundException,
|
||||
PipeTransform,
|
||||
} from '@nestjs/common';
|
||||
|
||||
import { ForbiddenIdError, NotInDBError } from '../../errors/errors';
|
||||
import { ConsoleLoggerService } from '../../logger/console-logger.service';
|
||||
import { Note } from '../../notes/note.entity';
|
||||
import { NotesService } from '../../notes/notes.service';
|
||||
|
||||
@Injectable()
|
||||
export class GetNotePipe implements PipeTransform<string, Promise<Note>> {
|
||||
constructor(
|
||||
private readonly logger: ConsoleLoggerService,
|
||||
private noteService: NotesService,
|
||||
) {
|
||||
this.logger.setContext(GetNotePipe.name);
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue