Add type management endpoints for machines
This commit introduces endpoints to add, remove, and list types associated with machines. It also includes the addition of the `TypeDto` class to handle type validations and updates HTTP response codes for the existing endpoints.
This commit is contained in:
parent
16ed8d3420
commit
030b5c814c
@ -14,13 +14,17 @@ import {
|
|||||||
UseGuards,
|
UseGuards,
|
||||||
} from "@nestjs/common";
|
} from "@nestjs/common";
|
||||||
import { AdminGuard } from "apps/backend/src/app/auth/auth.guard";
|
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";
|
import { MachinesService } from "apps/backend/src/app/machines/machines.service";
|
||||||
|
|
||||||
@Controller("machines")
|
@Controller("machines")
|
||||||
export class MachinesController {
|
export class MachinesController {
|
||||||
constructor(private readonly machineService: MachinesService) {}
|
constructor(private readonly machineService: MachinesService) {}
|
||||||
|
|
||||||
|
@HttpCode(HttpStatus.OK)
|
||||||
@Get("find")
|
@Get("find")
|
||||||
async findMany(
|
async findMany(
|
||||||
@Query("limit", new DefaultValuePipe(20), ParseIntPipe) limit: number,
|
@Query("limit", new DefaultValuePipe(20), ParseIntPipe) limit: number,
|
||||||
@ -36,15 +40,38 @@ export class MachinesController {
|
|||||||
return await this.machineService.create(body.machineName, body.machineType);
|
return await this.machineService.create(body.machineName, body.machineType);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@HttpCode(HttpStatus.ACCEPTED)
|
||||||
@UseGuards(AdminGuard)
|
@UseGuards(AdminGuard)
|
||||||
@Delete(":machineId")
|
@Delete(":machineId")
|
||||||
async deleteMachine(@Param("machineId") machineId: string) {}
|
async deleteMachine(@Param("machineId") machineId: string) {}
|
||||||
|
|
||||||
//TODO Type add for machine
|
@HttpCode(HttpStatus.ACCEPTED)
|
||||||
//TODO Type remove for machine
|
@UseGuards(AdminGuard)
|
||||||
//TODO Type list for machine
|
@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")
|
@Get("files/:machineId")
|
||||||
async getFilesForMachine(
|
async getFilesForMachine(
|
||||||
@Query("limit", new DefaultValuePipe(20), ParseIntPipe) limit: number,
|
@Query("limit", new DefaultValuePipe(20), ParseIntPipe) limit: number,
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import { MaxLength, MinLength } from "class-validator";
|
import { IsUUID, MaxLength, MinLength } from "class-validator";
|
||||||
|
|
||||||
export class CreateMachineDto {
|
export class CreateMachineDto {
|
||||||
@MaxLength(128)
|
@MaxLength(128)
|
||||||
@ -9,3 +9,8 @@ export class CreateMachineDto {
|
|||||||
@MinLength(2)
|
@MinLength(2)
|
||||||
machineType: string;
|
machineType: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export class TypeDto {
|
||||||
|
@IsUUID()
|
||||||
|
fileTypeId: string;
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user