Derive project device phases from category

This commit is contained in:
Julian Appel 2026-07-31 14:37:45 +02:00
parent 5fb81bab04
commit 1e3c721cfa
9 changed files with 101 additions and 80 deletions

View file

@ -23,6 +23,8 @@ import {
import type { CreateProjectDeviceInput } from "../../shared/validation/project-device.schemas.js";
import { respondWithProjectCommandError } from "./project-command.controller.js";
import { resolveProjectVoltage } from "../../domain/services/project-voltage.service.js";
import { resolveProjectDevicePhaseType } from "../../domain/services/project-device-placement.service.js";
import type { CircuitGroupCategory } from "../../shared/constants/circuit-group.js";
export async function listProjectDevicesByProject(req: Request, res: Response) {
const { projectId } = req.params;
@ -156,8 +158,10 @@ export async function copyGlobalDeviceToProject(req: Request, res: Response) {
const projectDevice = toProjectDeviceSnapshot(projectId, randomUUID(), {
name: source.name,
displayName: source.displayName,
phaseType: source.phaseCount === 3 ? "three_phase" : "single_phase",
category: source.category ?? undefined,
category: inferImportedProjectDeviceCategory(
source.category,
source.phaseCount
),
quantity: source.quantity,
powerPerUnit: source.installedPowerPerUnitKw,
simultaneityFactor: source.demandFactor,
@ -205,22 +209,34 @@ function toProjectDeviceValues(
threePhaseVoltageV: number;
}
) {
const phaseType = resolveProjectDevicePhaseType(input.category);
return {
name: input.name,
displayName: input.displayName,
phaseType: input.phaseType,
phaseType,
connectionKind: input.connectionKind ?? null,
costGroup: input.costGroup ?? null,
category: input.category ?? null,
category: input.category,
quantity: input.quantity,
powerPerUnit: input.powerPerUnit,
simultaneityFactor: input.simultaneityFactor,
cosPhi: input.cosPhi ?? null,
remark: input.remark ?? null,
voltageV: resolveProjectVoltage(input.phaseType, project),
voltageV: resolveProjectVoltage(phaseType, project),
};
}
function inferImportedProjectDeviceCategory(
category: string | null,
phaseCount: number | null
): CircuitGroupCategory {
const normalized = category?.trim().toLowerCase() ?? "";
if (normalized.includes("light") || normalized.includes("beleuchtung")) {
return "lighting";
}
return phaseCount === 3 ? "three_phase" : "single_phase";
}
export async function getProjectDeviceSyncPreview(req: Request, res: Response) {
const { projectId, projectDeviceId } = req.params;
if (typeof projectId !== "string" || typeof projectDeviceId !== "string") {