forked from jappel/leistungsbilanz-ts
Add configurable distribution supply types
This commit is contained in:
parent
194bc9c0b1
commit
b1a11397b3
43 changed files with 5697 additions and 126 deletions
|
|
@ -1,9 +1,13 @@
|
|||
import type { Request, Response } from "express";
|
||||
import { createDistributionBoardUpdateProjectCommand } from "../../domain/models/distribution-board-project-command.model.js";
|
||||
import {
|
||||
createDistributionBoardInsertProjectCommand,
|
||||
createDistributionBoardStructureSnapshot,
|
||||
} from "../../domain/models/distribution-board-structure-project-command.model.js";
|
||||
import { createDistributionBoardSchema } from "../../shared/validation/project-structure.schemas.js";
|
||||
import {
|
||||
createDistributionBoardSchema,
|
||||
updateDistributionBoardSchema,
|
||||
} from "../../shared/validation/project-structure.schemas.js";
|
||||
import { projectCommandService } from "../composition/project-command-stores.js";
|
||||
import { distributionBoardRepository } from "../composition/application-repositories.js";
|
||||
import { respondWithProjectCommandError } from "./project-command.controller.js";
|
||||
|
|
@ -31,7 +35,11 @@ export async function createDistributionBoard(req: Request, res: Response) {
|
|||
|
||||
const structure = createDistributionBoardStructureSnapshot(
|
||||
projectId,
|
||||
parsed.data.name
|
||||
parsed.data.name,
|
||||
{
|
||||
floorId: parsed.data.floorId,
|
||||
supplyType: parsed.data.supplyType,
|
||||
}
|
||||
);
|
||||
try {
|
||||
const result = projectCommandService.executeUser({
|
||||
|
|
@ -49,3 +57,43 @@ export async function createDistributionBoard(req: Request, res: Response) {
|
|||
return respondWithProjectCommandError(error, res);
|
||||
}
|
||||
}
|
||||
|
||||
export async function updateDistributionBoard(
|
||||
req: Request,
|
||||
res: Response
|
||||
) {
|
||||
const { projectId, distributionBoardId } = req.params;
|
||||
if (
|
||||
typeof projectId !== "string" ||
|
||||
typeof distributionBoardId !== "string"
|
||||
) {
|
||||
return res.status(400).json({ error: "Invalid distribution board id" });
|
||||
}
|
||||
const parsed = updateDistributionBoardSchema.safeParse(req.body);
|
||||
if (!parsed.success) {
|
||||
return res.status(400).json({ error: parsed.error.flatten() });
|
||||
}
|
||||
try {
|
||||
const result = projectCommandService.executeUser({
|
||||
projectId,
|
||||
expectedRevision: parsed.data.expectedRevision,
|
||||
description: "Verteilung bearbeiten",
|
||||
command: createDistributionBoardUpdateProjectCommand(
|
||||
distributionBoardId,
|
||||
{
|
||||
floorId: parsed.data.floorId,
|
||||
supplyType: parsed.data.supplyType,
|
||||
}
|
||||
),
|
||||
});
|
||||
const distributionBoard = (
|
||||
await distributionBoardRepository.listByProject(projectId)
|
||||
).find((board) => board.id === distributionBoardId);
|
||||
if (!distributionBoard) {
|
||||
return res.status(404).json({ error: "Distribution board not found" });
|
||||
}
|
||||
return res.json({ ...result, distributionBoard });
|
||||
} catch (error) {
|
||||
return respondWithProjectCommandError(error, res);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue