forked from jappel/leistungsbilanz-ts
Add editable project floors and rooms
This commit is contained in:
parent
1e3c721cfa
commit
1eed19ef6b
15 changed files with 743 additions and 80 deletions
|
|
@ -1,9 +1,15 @@
|
|||
import type { Request, Response } from "express";
|
||||
import {
|
||||
createProjectFloorDeleteProjectCommand,
|
||||
createProjectFloorInsertProjectCommand,
|
||||
createProjectFloorSnapshot,
|
||||
createProjectFloorUpdateProjectCommand,
|
||||
} from "../../domain/models/project-location-structure-project-command.model.js";
|
||||
import { createFloorSchema } from "../../shared/validation/project-structure.schemas.js";
|
||||
import {
|
||||
createFloorSchema,
|
||||
deleteProjectLocationSchema,
|
||||
updateFloorSchema,
|
||||
} from "../../shared/validation/project-structure.schemas.js";
|
||||
import { projectCommandService } from "../composition/project-command-stores.js";
|
||||
import { floorRepository } from "../composition/application-repositories.js";
|
||||
import { respondWithProjectCommandError } from "./project-command.controller.js";
|
||||
|
|
@ -50,3 +56,56 @@ export async function createFloor(req: Request, res: Response) {
|
|||
return respondWithProjectCommandError(error, res);
|
||||
}
|
||||
}
|
||||
|
||||
export async function updateFloor(req: Request, res: Response) {
|
||||
const { projectId, floorId } = req.params;
|
||||
if (typeof projectId !== "string" || typeof floorId !== "string") {
|
||||
return res.status(400).json({ error: "Invalid parameters" });
|
||||
}
|
||||
const parsed = updateFloorSchema.safeParse(req.body);
|
||||
if (!parsed.success) {
|
||||
return res.status(400).json({ error: parsed.error.flatten() });
|
||||
}
|
||||
const current = await floorRepository.findById(projectId, floorId);
|
||||
if (!current) {
|
||||
return res.status(404).json({ error: "Floor not found" });
|
||||
}
|
||||
const target = { ...current, name: parsed.data.name };
|
||||
try {
|
||||
const result = projectCommandService.executeUser({
|
||||
projectId,
|
||||
expectedRevision: parsed.data.expectedRevision,
|
||||
description: "Geschoss bearbeiten",
|
||||
command: createProjectFloorUpdateProjectCommand(current, target),
|
||||
});
|
||||
return res.json({ ...result, floor: target });
|
||||
} catch (error) {
|
||||
return respondWithProjectCommandError(error, res);
|
||||
}
|
||||
}
|
||||
|
||||
export async function deleteFloor(req: Request, res: Response) {
|
||||
const { projectId, floorId } = req.params;
|
||||
if (typeof projectId !== "string" || typeof floorId !== "string") {
|
||||
return res.status(400).json({ error: "Invalid parameters" });
|
||||
}
|
||||
const parsed = deleteProjectLocationSchema.safeParse(req.body);
|
||||
if (!parsed.success) {
|
||||
return res.status(400).json({ error: parsed.error.flatten() });
|
||||
}
|
||||
const current = await floorRepository.findById(projectId, floorId);
|
||||
if (!current) {
|
||||
return res.status(404).json({ error: "Floor not found" });
|
||||
}
|
||||
try {
|
||||
const result = projectCommandService.executeUser({
|
||||
projectId,
|
||||
expectedRevision: parsed.data.expectedRevision,
|
||||
description: "Geschoss löschen",
|
||||
command: createProjectFloorDeleteProjectCommand(current),
|
||||
});
|
||||
return res.json(result);
|
||||
} catch (error) {
|
||||
return respondWithProjectCommandError(error, res);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,9 +1,15 @@
|
|||
import type { Request, Response } from "express";
|
||||
import {
|
||||
createProjectRoomDeleteProjectCommand,
|
||||
createProjectRoomInsertProjectCommand,
|
||||
createProjectRoomSnapshot,
|
||||
createProjectRoomUpdateProjectCommand,
|
||||
} from "../../domain/models/project-location-structure-project-command.model.js";
|
||||
import { createRoomSchema } from "../../shared/validation/project-structure.schemas.js";
|
||||
import {
|
||||
createRoomSchema,
|
||||
deleteProjectLocationSchema,
|
||||
updateRoomSchema,
|
||||
} from "../../shared/validation/project-structure.schemas.js";
|
||||
import { projectCommandService } from "../composition/project-command-stores.js";
|
||||
import { roomRepository } from "../composition/application-repositories.js";
|
||||
import { respondWithProjectCommandError } from "./project-command.controller.js";
|
||||
|
|
@ -42,3 +48,61 @@ export async function createRoom(req: Request, res: Response) {
|
|||
return respondWithProjectCommandError(error, res);
|
||||
}
|
||||
}
|
||||
|
||||
export async function updateRoom(req: Request, res: Response) {
|
||||
const { projectId, roomId } = req.params;
|
||||
if (typeof projectId !== "string" || typeof roomId !== "string") {
|
||||
return res.status(400).json({ error: "Invalid parameters" });
|
||||
}
|
||||
const parsed = updateRoomSchema.safeParse(req.body);
|
||||
if (!parsed.success) {
|
||||
return res.status(400).json({ error: parsed.error.flatten() });
|
||||
}
|
||||
const current = await roomRepository.findById(projectId, roomId);
|
||||
if (!current) {
|
||||
return res.status(404).json({ error: "Room not found" });
|
||||
}
|
||||
const target = {
|
||||
...current,
|
||||
floorId: parsed.data.floorId,
|
||||
roomNumber: parsed.data.roomNumber,
|
||||
roomName: parsed.data.roomName,
|
||||
};
|
||||
try {
|
||||
const result = projectCommandService.executeUser({
|
||||
projectId,
|
||||
expectedRevision: parsed.data.expectedRevision,
|
||||
description: "Raum bearbeiten",
|
||||
command: createProjectRoomUpdateProjectCommand(current, target),
|
||||
});
|
||||
return res.json({ ...result, room: target });
|
||||
} catch (error) {
|
||||
return respondWithProjectCommandError(error, res);
|
||||
}
|
||||
}
|
||||
|
||||
export async function deleteRoom(req: Request, res: Response) {
|
||||
const { projectId, roomId } = req.params;
|
||||
if (typeof projectId !== "string" || typeof roomId !== "string") {
|
||||
return res.status(400).json({ error: "Invalid parameters" });
|
||||
}
|
||||
const parsed = deleteProjectLocationSchema.safeParse(req.body);
|
||||
if (!parsed.success) {
|
||||
return res.status(400).json({ error: parsed.error.flatten() });
|
||||
}
|
||||
const current = await roomRepository.findById(projectId, roomId);
|
||||
if (!current) {
|
||||
return res.status(404).json({ error: "Room not found" });
|
||||
}
|
||||
try {
|
||||
const result = projectCommandService.executeUser({
|
||||
projectId,
|
||||
expectedRevision: parsed.data.expectedRevision,
|
||||
description: "Raum löschen",
|
||||
command: createProjectRoomDeleteProjectCommand(current),
|
||||
});
|
||||
return res.json(result);
|
||||
} catch (error) {
|
||||
return respondWithProjectCommandError(error, res);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -13,8 +13,8 @@ import {
|
|||
updateDistributionBoard,
|
||||
} from "../controllers/distribution-board.controller.js";
|
||||
import { listCircuitListsByProject } from "../controllers/circuit-list.controller.js";
|
||||
import { createFloor, listFloorsByProject } from "../controllers/floor.controller.js";
|
||||
import { createRoom, listRoomsByProject } from "../controllers/room.controller.js";
|
||||
import { createFloor, deleteFloor, listFloorsByProject, updateFloor } from "../controllers/floor.controller.js";
|
||||
import { createRoom, deleteRoom, listRoomsByProject, updateRoom } from "../controllers/room.controller.js";
|
||||
import { getCircuitTree } from "../controllers/circuit-tree.controller.js";
|
||||
import {
|
||||
getProjectHistory,
|
||||
|
|
@ -74,5 +74,9 @@ projectRouter.get("/:projectId/circuit-lists", listCircuitListsByProject);
|
|||
projectRouter.get("/:projectId/circuit-lists/:circuitListId/tree", getCircuitTree);
|
||||
projectRouter.get("/:projectId/floors", listFloorsByProject);
|
||||
projectRouter.post("/:projectId/floors", createFloor);
|
||||
projectRouter.put("/:projectId/floors/:floorId", updateFloor);
|
||||
projectRouter.delete("/:projectId/floors/:floorId", deleteFloor);
|
||||
projectRouter.get("/:projectId/rooms", listRoomsByProject);
|
||||
projectRouter.post("/:projectId/rooms", createRoom);
|
||||
projectRouter.put("/:projectId/rooms/:roomId", updateRoom);
|
||||
projectRouter.delete("/:projectId/rooms/:roomId", deleteRoom);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue