forked from jappel/leistungsbilanz-ts
Circuits can now record that they deliberately have no protection device (type NONE, shown as "–"), separate from circuits whose protection is still open. Migration 0017 makes rated_current_a nullable. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
48 lines
1.6 KiB
TypeScript
48 lines
1.6 KiB
TypeScript
import type {
|
|
CircuitProtectionSnapshot,
|
|
} from "../../domain/models/circuit-protection-project-command.model";
|
|
import { createDefaultCircuitProtection } from "../../domain/services/protection-device-defaults";
|
|
import type { CircuitGroupCategory } from "../../shared/constants/circuit-group";
|
|
import { noCircuitProtectionDeviceType } from "../../shared/constants/protection-device";
|
|
import type {
|
|
CircuitTreeCircuitProtectionDeviceDto,
|
|
} from "../types";
|
|
|
|
export function toCircuitProtectionSnapshot(
|
|
circuitId: string,
|
|
protection: CircuitTreeCircuitProtectionDeviceDto
|
|
): CircuitProtectionSnapshot {
|
|
if (protection.type === noCircuitProtectionDeviceType) {
|
|
return {
|
|
circuitId,
|
|
type: noCircuitProtectionDeviceType,
|
|
ratedCurrentA: null,
|
|
fuseUtilizationCategory: null,
|
|
tripCharacteristic: null,
|
|
rcdType: null,
|
|
ratedResidualCurrentMa: null,
|
|
};
|
|
}
|
|
return {
|
|
circuitId,
|
|
type: protection.type,
|
|
ratedCurrentA: protection.ratedCurrentA,
|
|
fuseUtilizationCategory:
|
|
protection.fuseUtilizationCategory ?? null,
|
|
tripCharacteristic: protection.tripCharacteristic ?? null,
|
|
rcdType: protection.rcdType ?? null,
|
|
ratedResidualCurrentMa:
|
|
protection.ratedResidualCurrentMa ?? null,
|
|
};
|
|
}
|
|
|
|
export function getCircuitProtectionEditorInitialValue(
|
|
category: CircuitGroupCategory | undefined,
|
|
protection: CircuitTreeCircuitProtectionDeviceDto | undefined
|
|
): CircuitTreeCircuitProtectionDeviceDto {
|
|
if (protection) {
|
|
return protection;
|
|
}
|
|
const fallback = createDefaultCircuitProtection(category ?? "lighting");
|
|
return { ...fallback };
|
|
}
|