forked from jappel/leistungsbilanz-ts
100 lines
3.5 KiB
TypeScript
100 lines
3.5 KiB
TypeScript
import type {
|
|
CircuitDeviceRowSnapshot,
|
|
} from "../../domain/models/circuit-device-row-structure-project-command.model.js";
|
|
import type {
|
|
CircuitSnapshot,
|
|
} from "../../domain/models/circuit-structure-project-command.model.js";
|
|
import type {
|
|
CreateCircuitDeviceRowInputDto,
|
|
CreateCircuitInputDto,
|
|
} from "../types.js";
|
|
import type { CircuitGroupCategory } from "../../shared/constants/circuit-group";
|
|
import { createDefaultCircuitProtection } from "../../domain/services/protection-device-defaults";
|
|
|
|
export function buildCircuitDeviceRowInsertSnapshot(input: {
|
|
id: string;
|
|
circuitId: string;
|
|
values: CreateCircuitDeviceRowInputDto;
|
|
defaultSortOrder: number;
|
|
}): CircuitDeviceRowSnapshot {
|
|
const { id, circuitId, values, defaultSortOrder } = input;
|
|
return {
|
|
id,
|
|
circuitId,
|
|
linkedProjectDeviceId: values.linkedProjectDeviceId ?? null,
|
|
sortOrder: values.sortOrder ?? defaultSortOrder,
|
|
name: values.name,
|
|
displayName: values.displayName,
|
|
phaseType: values.phaseType ?? null,
|
|
connectionKind: values.connectionKind ?? null,
|
|
costGroup: values.costGroup ?? null,
|
|
category: values.category ?? null,
|
|
level: values.level ?? null,
|
|
roomId: values.roomId ?? null,
|
|
roomNumberSnapshot: values.roomNumberSnapshot ?? null,
|
|
roomNameSnapshot: values.roomNameSnapshot ?? null,
|
|
quantity: values.quantity,
|
|
powerPerUnit: values.powerPerUnit,
|
|
simultaneityFactor: values.simultaneityFactor,
|
|
cosPhi: values.cosPhi ?? null,
|
|
remark: values.remark ?? null,
|
|
overriddenFields: values.overriddenFields ?? null,
|
|
};
|
|
}
|
|
|
|
export function buildCircuitInsertSnapshot(input: {
|
|
id: string;
|
|
circuitListId: string;
|
|
values: CreateCircuitInputDto;
|
|
deviceRows: CircuitDeviceRowSnapshot[];
|
|
category?: CircuitGroupCategory;
|
|
}): CircuitSnapshot {
|
|
const { id, circuitListId, values, deviceRows, category } = input;
|
|
const defaultProtection = category
|
|
? createDefaultCircuitProtection(category)
|
|
: null;
|
|
return {
|
|
id,
|
|
circuitListId,
|
|
sectionId: values.sectionId,
|
|
equipmentIdentifier: values.equipmentIdentifier,
|
|
displayName: values.displayName ?? null,
|
|
sortOrder: values.sortOrder,
|
|
cableType: values.cableType ?? null,
|
|
cableCrossSection: values.cableCrossSection ?? null,
|
|
cableLength: values.cableLength ?? null,
|
|
rcdAssignment: values.rcdAssignment ?? null,
|
|
terminalDesignation: values.terminalDesignation ?? null,
|
|
voltage: values.voltage ?? null,
|
|
controlRequirement: values.controlRequirement ?? null,
|
|
status: values.status ?? null,
|
|
isReserve: deviceRows.length === 0,
|
|
remark: values.remark ?? null,
|
|
deviceRows,
|
|
...(defaultProtection
|
|
? {
|
|
protectionDevice: {
|
|
circuitId: id,
|
|
type: defaultProtection.type,
|
|
ratedCurrentA: defaultProtection.ratedCurrentA,
|
|
fuseUtilizationCategory:
|
|
"fuseUtilizationCategory" in defaultProtection
|
|
? defaultProtection.fuseUtilizationCategory
|
|
: null,
|
|
tripCharacteristic:
|
|
"tripCharacteristic" in defaultProtection
|
|
? defaultProtection.tripCharacteristic
|
|
: null,
|
|
rcdType:
|
|
"rcdType" in defaultProtection
|
|
? defaultProtection.rcdType
|
|
: null,
|
|
ratedResidualCurrentMa:
|
|
"ratedResidualCurrentMa" in defaultProtection
|
|
? defaultProtection.ratedResidualCurrentMa
|
|
: null,
|
|
},
|
|
}
|
|
: {}),
|
|
};
|
|
}
|