From 0c94d16b1945d1ed6a34698684ce7a7230c9ab8c Mon Sep 17 00:00:00 2001 From: Mathis Date: Tue, 8 Oct 2024 13:38:29 +0200 Subject: [PATCH] Refactor authors controller and add admin guard Renamed routes and incorporated `AdminGuard` for deletion. Adjusted parameter names and simplified function bodies to improve readability and security. --- .../src/app/authors/authors.controller.ts | 32 +++++++++---------- 1 file changed, 15 insertions(+), 17 deletions(-) diff --git a/apps/backend/src/app/authors/authors.controller.ts b/apps/backend/src/app/authors/authors.controller.ts index ec80ac9..c447be3 100644 --- a/apps/backend/src/app/authors/authors.controller.ts +++ b/apps/backend/src/app/authors/authors.controller.ts @@ -6,39 +6,37 @@ import { Param, ParseIntPipe, Post, - Query, -} from "@nestjs/common"; + Query, UseGuards +} from '@nestjs/common'; import { AuthorsService } from "apps/backend/src/app/authors/authors.service"; +import { AdminGuard } from 'apps/backend/src/app/auth/auth.guard'; @Controller("authors") export class AuthorsController { constructor(private readonly authorService: AuthorsService) {} - @Get() + @Get("find") async findMany( @Query("limit", new DefaultValuePipe(20), ParseIntPipe) limit: number, @Query("offset", new DefaultValuePipe(0), ParseIntPipe) offset: number, @Query("search", new DefaultValuePipe("")) search: string, - ) { - const query = { limit, offset, search }; - } + ) {} - //POST a new group + //TODO DTO @Post("new") async newAuthor() {} - //DELETE a group - @Delete(":authorId") - async deleteAuthor(@Param("authorId") authorId: string) {} + @UseGuards(AdminGuard) + @Delete(":autor") + async deleteAuthor(@Param("machineId") machineId: string) {} - //GET files associated to authors with limit and offset - @Get(":authorId") - async getForAuthor( + //TODO Patch + + @Get(":author/files") + async getFilesForAuthor( @Query("limit", new DefaultValuePipe(20), ParseIntPipe) limit: number, @Query("offset", new DefaultValuePipe(0), ParseIntPipe) offset: number, @Query("search", new DefaultValuePipe("")) search: string, - @Param("authorId") authorId: string, - ) { - const query = { limit, offset, search }; - } + @Param("machineId") machineId: string, + ) {} }