Persist project locations

This commit is contained in:
Julian Appel 2026-07-26 10:56:29 +02:00
parent 1cf26a932e
commit ac465a1cc0
23 changed files with 1313 additions and 101 deletions

View file

@ -1,6 +1,12 @@
import type { Request, Response } from "express";
import { FloorRepository } from "../../db/repositories/floor.repository.js";
import {
createProjectFloorInsertProjectCommand,
createProjectFloorSnapshot,
} from "../../domain/models/project-location-structure-project-command.model.js";
import { createFloorSchema } from "../../shared/validation/project-structure.schemas.js";
import { projectCommandService } from "../composition/project-command-stores.js";
import { respondWithProjectCommandError } from "./project-command.controller.js";
const floorRepository = new FloorRepository();
@ -25,6 +31,24 @@ export async function createFloor(req: Request, res: Response) {
return res.status(400).json({ error: parsed.error.flatten() });
}
const floor = await floorRepository.create(projectId, parsed.data.name);
return res.status(201).json(floor);
const existingFloors = await floorRepository.listByProject(projectId);
const nextSortOrder = existingFloors.length
? Math.max(...existingFloors.map((floor) => floor.sortOrder)) + 1
: 0;
const floor = createProjectFloorSnapshot(
projectId,
parsed.data.name,
nextSortOrder
);
try {
const result = projectCommandService.executeUser({
projectId,
expectedRevision: parsed.data.expectedRevision,
description: "Geschoss anlegen",
command: createProjectFloorInsertProjectCommand(floor),
});
return res.status(201).json({ ...result, floor });
} catch (error) {
return respondWithProjectCommandError(error, res);
}
}