diff --git a/apps/backend/src/app/machines/machines.controller.ts b/apps/backend/src/app/machines/machines.controller.ts index a2d158d..0548c8b 100644 --- a/apps/backend/src/app/machines/machines.controller.ts +++ b/apps/backend/src/app/machines/machines.controller.ts @@ -14,13 +14,17 @@ import { UseGuards, } from "@nestjs/common"; import { AdminGuard } from "apps/backend/src/app/auth/auth.guard"; -import { CreateMachineDto } from "apps/backend/src/app/machines/machines.dto"; +import { + CreateMachineDto, + TypeDto, +} from "apps/backend/src/app/machines/machines.dto"; import { MachinesService } from "apps/backend/src/app/machines/machines.service"; @Controller("machines") export class MachinesController { constructor(private readonly machineService: MachinesService) {} + @HttpCode(HttpStatus.OK) @Get("find") async findMany( @Query("limit", new DefaultValuePipe(20), ParseIntPipe) limit: number, @@ -36,15 +40,38 @@ export class MachinesController { return await this.machineService.create(body.machineName, body.machineType); } + @HttpCode(HttpStatus.ACCEPTED) @UseGuards(AdminGuard) @Delete(":machineId") async deleteMachine(@Param("machineId") machineId: string) {} - //TODO Type add for machine - //TODO Type remove for machine - //TODO Type list for machine + @HttpCode(HttpStatus.ACCEPTED) + @UseGuards(AdminGuard) + @Post("types/:machineId") + async addTypeToMachine( + @Param("machineId") machineId: string, + @Body() body: TypeDto, + ) { + return await this.machineService.addFileType(machineId, body.fileTypeId); + } - @HttpCode(HttpStatus.OK) + @HttpCode(HttpStatus.ACCEPTED) + @UseGuards(AdminGuard) + @Delete("types/:machineId") + async remTypeToMachine( + @Param("machineId") machineId: string, + @Body() body: TypeDto, + ) { + return await this.machineService.removeFileType(machineId, body.fileTypeId); + } + + @HttpCode(HttpStatus.FOUND) + @Get("types/:machineId") + async getTypesOfMachine(@Param("machineId") machineId: string) { + return await this.machineService.getFilesTypes(machineId); + } + + @HttpCode(HttpStatus.FOUND) @Get("files/:machineId") async getFilesForMachine( @Query("limit", new DefaultValuePipe(20), ParseIntPipe) limit: number, diff --git a/apps/backend/src/app/machines/machines.dto.ts b/apps/backend/src/app/machines/machines.dto.ts index a93e519..bccdcd5 100644 --- a/apps/backend/src/app/machines/machines.dto.ts +++ b/apps/backend/src/app/machines/machines.dto.ts @@ -1,4 +1,4 @@ -import { MaxLength, MinLength } from "class-validator"; +import { IsUUID, MaxLength, MinLength } from "class-validator"; export class CreateMachineDto { @MaxLength(128) @@ -9,3 +9,8 @@ export class CreateMachineDto { @MinLength(2) machineType: string; } + +export class TypeDto { + @IsUUID() + fileTypeId: string; +}