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,
|
||||
} 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,
|
||||
|
@ -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;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user