forked from jappel/leistungsbilanz-ts
36 lines
1.1 KiB
TypeScript
36 lines
1.1 KiB
TypeScript
import type { CreateConsumerInput } from "../../shared/validation/consumer.schemas.js";
|
|
|
|
type ProjectDeviceForLinking = {
|
|
displayName: string;
|
|
category: string | null;
|
|
quantity: number;
|
|
installedPowerPerUnitKw: number;
|
|
demandFactor: number;
|
|
phaseCount: number | null;
|
|
powerFactor: number | null;
|
|
note: string | null;
|
|
};
|
|
|
|
export function applyLinkedProjectDeviceValues(
|
|
input: CreateConsumerInput,
|
|
projectDevice: ProjectDeviceForLinking | null
|
|
): CreateConsumerInput {
|
|
if (!input.projectDeviceId || !input.isLinkedToDevice || !projectDevice) {
|
|
return input;
|
|
}
|
|
|
|
return {
|
|
...input,
|
|
name: projectDevice.displayName,
|
|
category: projectDevice.category ?? undefined,
|
|
quantity: projectDevice.quantity,
|
|
installedPowerPerUnitKw: projectDevice.installedPowerPerUnitKw,
|
|
demandFactor: projectDevice.demandFactor,
|
|
phaseCount:
|
|
projectDevice.phaseCount === 1 || projectDevice.phaseCount === 3
|
|
? (projectDevice.phaseCount as 1 | 3)
|
|
: undefined,
|
|
powerFactor: projectDevice.powerFactor ?? undefined,
|
|
note: projectDevice.note ?? undefined,
|
|
};
|
|
}
|