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);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue