Add external row quantity foundation

This commit is contained in:
Julian Appel 2026-08-02 18:26:22 +02:00
parent bc2bc7ece5
commit dac19b093c
30 changed files with 2750 additions and 22 deletions

View file

@ -22,6 +22,7 @@ export interface CircuitDeviceRowSnapshot {
roomNumberSnapshot: string | null;
roomNameSnapshot: string | null;
quantity: number;
manualQuantity?: number;
powerPerUnit: number;
simultaneityFactor: number;
cosPhi: number | null;
@ -57,10 +58,14 @@ export type CircuitDeviceRowStructureProjectCommand =
export function createCircuitDeviceRowInsertProjectCommand(
row: CircuitDeviceRowSnapshot
): CircuitDeviceRowInsertProjectCommand {
const normalizedRow = {
...row,
manualQuantity: row.manualQuantity ?? row.quantity,
};
const command: CircuitDeviceRowInsertProjectCommand = {
schemaVersion: circuitDeviceRowStructureCommandSchemaVersion,
type: circuitDeviceRowInsertCommandType,
payload: { row },
payload: { row: normalizedRow },
};
assertCircuitDeviceRowInsertProjectCommand(command);
return command;
@ -117,7 +122,13 @@ export function assertCircuitDeviceRowInsertProjectCommand(
] as const) {
assertNullableString(row[field], `row.${field}`);
}
assertNonNegativeNumber(row.quantity, "row.quantity");
const quantity = row.quantity;
assertNonNegativeNumber(quantity, "row.quantity");
const manualQuantity = row.manualQuantity ?? quantity;
assertNonNegativeNumber(manualQuantity, "row.manualQuantity");
if (manualQuantity > quantity) {
throw new Error("row.manualQuantity must not exceed row.quantity.");
}
assertNonNegativeNumber(row.powerPerUnit, "row.powerPerUnit");
assertNonNegativeNumber(
row.simultaneityFactor,
@ -172,7 +183,10 @@ function assertFiniteNumber(
}
}
function assertNonNegativeNumber(value: unknown, field: string) {
function assertNonNegativeNumber(
value: unknown,
field: string
): asserts value is number {
assertFiniteNumber(value, field);
if (value < 0) {
throw new Error(`${field} must not be negative.`);