Use Req decorator instead of Request

This avoids a clash with the Request type from express

Signed-off-by: David Mehren <git@herrmehren.de>
This commit is contained in:
David Mehren 2021-02-23 21:20:01 +01:00
parent 2b14ad92cd
commit b78c94c3a1
No known key found for this signature in database
GPG key ID: 185982BA4C42B7C3
3 changed files with 20 additions and 20 deletions

View file

@ -14,7 +14,7 @@ import {
Param, Param,
Put, Put,
UseGuards, UseGuards,
Request, Req,
} from '@nestjs/common'; } from '@nestjs/common';
import { HistoryEntryUpdateDto } from '../../../history/history-entry-update.dto'; import { HistoryEntryUpdateDto } from '../../../history/history-entry-update.dto';
import { HistoryService } from '../../../history/history.service'; import { HistoryService } from '../../../history/history.service';
@ -43,7 +43,7 @@ export class MeController {
@UseGuards(TokenAuthGuard) @UseGuards(TokenAuthGuard)
@Get() @Get()
async getMe(@Request() req): Promise<UserInfoDto> { async getMe(@Req() req): Promise<UserInfoDto> {
return this.usersService.toUserDto( return this.usersService.toUserDto(
await this.usersService.getUserByUsername(req.user.userName), await this.usersService.getUserByUsername(req.user.userName),
); );
@ -51,7 +51,7 @@ export class MeController {
@UseGuards(TokenAuthGuard) @UseGuards(TokenAuthGuard)
@Get('history') @Get('history')
async getUserHistory(@Request() req): Promise<HistoryEntryDto[]> { async getUserHistory(@Req() req): Promise<HistoryEntryDto[]> {
const foundEntries = await this.historyService.getEntriesByUser(req.user); const foundEntries = await this.historyService.getEntriesByUser(req.user);
return await Promise.all( return await Promise.all(
foundEntries.map( foundEntries.map(
@ -63,7 +63,7 @@ export class MeController {
@UseGuards(TokenAuthGuard) @UseGuards(TokenAuthGuard)
@Put('history/:note') @Put('history/:note')
async updateHistoryEntry( async updateHistoryEntry(
@Request() req, @Req() req,
@Param('note') note: string, @Param('note') note: string,
@Body() entryUpdateDto: HistoryEntryUpdateDto, @Body() entryUpdateDto: HistoryEntryUpdateDto,
): Promise<HistoryEntryDto> { ): Promise<HistoryEntryDto> {
@ -87,7 +87,7 @@ export class MeController {
@UseGuards(TokenAuthGuard) @UseGuards(TokenAuthGuard)
@Delete('history/:note') @Delete('history/:note')
@HttpCode(204) @HttpCode(204)
deleteHistoryEntry(@Request() req, @Param('note') note: string) { deleteHistoryEntry(@Req() req, @Param('note') note: string) {
// ToDo: Check if user is allowed to delete note // ToDo: Check if user is allowed to delete note
try { try {
return this.historyService.deleteHistoryEntry(note, req.user); return this.historyService.deleteHistoryEntry(note, req.user);
@ -101,7 +101,7 @@ export class MeController {
@UseGuards(TokenAuthGuard) @UseGuards(TokenAuthGuard)
@Get('notes') @Get('notes')
async getMyNotes(@Request() req): Promise<NoteMetadataDto[]> { async getMyNotes(@Req() req): Promise<NoteMetadataDto[]> {
const notes = this.notesService.getUserNotes(req.user); const notes = this.notesService.getUserNotes(req.user);
return await Promise.all( return await Promise.all(
notes.map((note) => this.notesService.toNoteMetadataDto(note)), notes.map((note) => this.notesService.toNoteMetadataDto(note)),

View file

@ -13,7 +13,7 @@ import {
NotFoundException, NotFoundException,
Param, Param,
Post, Post,
Request, Req,
UnauthorizedException, UnauthorizedException,
UploadedFile, UploadedFile,
UseGuards, UseGuards,
@ -48,7 +48,7 @@ export class MediaController {
@Post() @Post()
@UseInterceptors(FileInterceptor('file')) @UseInterceptors(FileInterceptor('file'))
async uploadMedia( async uploadMedia(
@Request() req, @Req() req,
@UploadedFile() file: MulterFile, @UploadedFile() file: MulterFile,
@Headers('HedgeDoc-Note') noteId: string, @Headers('HedgeDoc-Note') noteId: string,
): Promise<MediaUploadUrlDto> { ): Promise<MediaUploadUrlDto> {
@ -80,7 +80,7 @@ export class MediaController {
@UseGuards(TokenAuthGuard) @UseGuards(TokenAuthGuard)
@Delete(':filename') @Delete(':filename')
async deleteMedia( async deleteMedia(
@Request() req, @Req() req,
@Param('filename') filename: string, @Param('filename') filename: string,
): Promise<void> { ): Promise<void> {
const username = req.user.userName; const username = req.user.userName;

View file

@ -15,7 +15,7 @@ import {
Param, Param,
Post, Post,
Put, Put,
Request, Req,
UnauthorizedException, UnauthorizedException,
UseGuards, UseGuards,
} from '@nestjs/common'; } from '@nestjs/common';
@ -59,7 +59,7 @@ export class NotesController {
@UseGuards(TokenAuthGuard) @UseGuards(TokenAuthGuard)
@Post() @Post()
async createNote( async createNote(
@Request() req, @Req() req,
@MarkdownBody() text: string, @MarkdownBody() text: string,
): Promise<NoteDto> { ): Promise<NoteDto> {
// ToDo: provide user for createNoteDto // ToDo: provide user for createNoteDto
@ -75,7 +75,7 @@ export class NotesController {
@UseGuards(TokenAuthGuard) @UseGuards(TokenAuthGuard)
@Get(':noteIdOrAlias') @Get(':noteIdOrAlias')
async getNote( async getNote(
@Request() req, @Req() req,
@Param('noteIdOrAlias') noteIdOrAlias: string, @Param('noteIdOrAlias') noteIdOrAlias: string,
): Promise<NoteDto> { ): Promise<NoteDto> {
let note: Note; let note: Note;
@ -97,7 +97,7 @@ export class NotesController {
@UseGuards(TokenAuthGuard) @UseGuards(TokenAuthGuard)
@Post(':noteAlias') @Post(':noteAlias')
async createNamedNote( async createNamedNote(
@Request() req, @Req() req,
@Param('noteAlias') noteAlias: string, @Param('noteAlias') noteAlias: string,
@MarkdownBody() text: string, @MarkdownBody() text: string,
): Promise<NoteDto> { ): Promise<NoteDto> {
@ -120,7 +120,7 @@ export class NotesController {
@UseGuards(TokenAuthGuard) @UseGuards(TokenAuthGuard)
@Delete(':noteIdOrAlias') @Delete(':noteIdOrAlias')
async deleteNote( async deleteNote(
@Request() req, @Req() req,
@Param('noteIdOrAlias') noteIdOrAlias: string, @Param('noteIdOrAlias') noteIdOrAlias: string,
): Promise<void> { ): Promise<void> {
try { try {
@ -143,7 +143,7 @@ export class NotesController {
@UseGuards(TokenAuthGuard) @UseGuards(TokenAuthGuard)
@Put(':noteIdOrAlias') @Put(':noteIdOrAlias')
async updateNote( async updateNote(
@Request() req, @Req() req,
@Param('noteIdOrAlias') noteIdOrAlias: string, @Param('noteIdOrAlias') noteIdOrAlias: string,
@MarkdownBody() text: string, @MarkdownBody() text: string,
): Promise<NoteDto> { ): Promise<NoteDto> {
@ -168,7 +168,7 @@ export class NotesController {
@Get(':noteIdOrAlias/content') @Get(':noteIdOrAlias/content')
@Header('content-type', 'text/markdown') @Header('content-type', 'text/markdown')
async getNoteContent( async getNoteContent(
@Request() req, @Req() req,
@Param('noteIdOrAlias') noteIdOrAlias: string, @Param('noteIdOrAlias') noteIdOrAlias: string,
): Promise<string> { ): Promise<string> {
try { try {
@ -188,7 +188,7 @@ export class NotesController {
@UseGuards(TokenAuthGuard) @UseGuards(TokenAuthGuard)
@Get(':noteIdOrAlias/metadata') @Get(':noteIdOrAlias/metadata')
async getNoteMetadata( async getNoteMetadata(
@Request() req, @Req() req,
@Param('noteIdOrAlias') noteIdOrAlias: string, @Param('noteIdOrAlias') noteIdOrAlias: string,
): Promise<NoteMetadataDto> { ): Promise<NoteMetadataDto> {
try { try {
@ -211,7 +211,7 @@ export class NotesController {
@UseGuards(TokenAuthGuard) @UseGuards(TokenAuthGuard)
@Put(':noteIdOrAlias/metadata/permissions') @Put(':noteIdOrAlias/metadata/permissions')
async updateNotePermissions( async updateNotePermissions(
@Request() req, @Req() req,
@Param('noteIdOrAlias') noteIdOrAlias: string, @Param('noteIdOrAlias') noteIdOrAlias: string,
@Body() updateDto: NotePermissionsUpdateDto, @Body() updateDto: NotePermissionsUpdateDto,
): Promise<NotePermissionsDto> { ): Promise<NotePermissionsDto> {
@ -234,7 +234,7 @@ export class NotesController {
@UseGuards(TokenAuthGuard) @UseGuards(TokenAuthGuard)
@Get(':noteIdOrAlias/revisions') @Get(':noteIdOrAlias/revisions')
async getNoteRevisions( async getNoteRevisions(
@Request() req, @Req() req,
@Param('noteIdOrAlias') noteIdOrAlias: string, @Param('noteIdOrAlias') noteIdOrAlias: string,
): Promise<RevisionMetadataDto[]> { ): Promise<RevisionMetadataDto[]> {
try { try {
@ -259,7 +259,7 @@ export class NotesController {
@UseGuards(TokenAuthGuard) @UseGuards(TokenAuthGuard)
@Get(':noteIdOrAlias/revisions/:revisionId') @Get(':noteIdOrAlias/revisions/:revisionId')
async getNoteRevision( async getNoteRevision(
@Request() req, @Req() req,
@Param('noteIdOrAlias') noteIdOrAlias: string, @Param('noteIdOrAlias') noteIdOrAlias: string,
@Param('revisionId') revisionId: number, @Param('revisionId') revisionId: number,
): Promise<RevisionDto> { ): Promise<RevisionDto> {