Remove legacy consumer API

This commit is contained in:
2026-07-23 20:00:48 +02:00
parent 04c299e3f2
commit 3fbf3ac622
30 changed files with 76 additions and 1089 deletions
@@ -1,29 +0,0 @@
export interface PowerInput {
quantity: number;
installedPowerPerUnitKw: number;
demandFactor: number;
}
export interface CurrentInput {
demandPowerKw: number;
voltageV: number;
phaseCount: 1 | 3;
powerFactor: number;
}
export function calculateInstalledPowerKw(input: PowerInput): number {
return input.quantity * input.installedPowerPerUnitKw;
}
export function calculateDemandPowerKw(input: PowerInput): number {
return calculateInstalledPowerKw(input) * input.demandFactor;
}
export function calculateCurrentA(input: CurrentInput): number {
const powerW = input.demandPowerKw * 1000;
if (input.phaseCount === 1) {
return powerW / (input.voltageV * input.powerFactor);
}
return powerW / (Math.sqrt(3) * input.voltageV * input.powerFactor);
}
-34
View File
@@ -1,34 +0,0 @@
export interface Consumer {
id: string;
projectId: string;
distributionBoardId?: string;
circuitListId?: string;
projectDeviceId?: string;
isLinkedToDevice?: boolean;
roomId?: string;
roomNumber?: string;
roomName?: string;
floorId?: string;
floorName?: string;
circuitNumber?: string;
description?: string;
name: string;
category?: string;
deviceType?: string;
phaseType?: string;
tradeOrCostGroup?: string;
group?: string;
protectionType?: string;
protectionRatedCurrent?: number;
protectionCharacteristic?: string;
cableType?: string;
cableCrossSection?: string;
comment?: string;
quantity: number;
installedPowerPerUnitKw: number;
demandFactor: number;
voltageV?: number;
phaseCount?: 1 | 3;
powerFactor?: number;
note?: string;
}
@@ -1,36 +0,0 @@
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,
};
}
@@ -1,7 +1,6 @@
import { CircuitRepository } from "../../db/repositories/circuit.repository.js";
import { CircuitListRepository } from "../../db/repositories/circuit-list.repository.js";
import { CircuitSectionRepository } from "../../db/repositories/circuit-section.repository.js";
import { ConsumerRepository } from "../../db/repositories/consumer.repository.js";
import {
LegacyConsumerMigrationRepository,
type LegacyMigrationCircuitPersistenceInput,
@@ -14,7 +13,11 @@ import {
normalizeCircuitNumber,
} from "./legacy-consumer-migration-planner.js";
type LegacyConsumerRow = Awaited<ReturnType<ConsumerRepository["listByCircuitList"]>>[number];
type LegacyConsumerRow = Awaited<
ReturnType<
LegacyConsumerMigrationRepository["listSourceConsumersByCircuitList"]
>
>[number];
function parseEquipmentSequence(equipmentIdentifier: string, prefix: string): number | null {
if (!equipmentIdentifier.startsWith(prefix)) {
@@ -32,7 +35,6 @@ export class LegacyConsumerMigrationService {
private readonly circuitListRepository = new CircuitListRepository();
private readonly sectionRepository = new CircuitSectionRepository();
private readonly circuitRepository = new CircuitRepository();
private readonly consumerRepository = new ConsumerRepository();
private readonly roomRepository = new RoomRepository();
constructor(
@@ -60,7 +62,10 @@ export class LegacyConsumerMigrationService {
existingCircuits.map((circuit) => circuit.equipmentIdentifier.toUpperCase())
);
const legacyConsumers = await this.consumerRepository.listByCircuitList(circuitListId);
const legacyConsumers =
await this.migrationRepository.listSourceConsumersByCircuitList(
circuitListId
);
const rooms = await this.roomRepository.listByProject(projectId);
const roomById = new Map(rooms.map((room) => [room.id, room]));
@@ -1,62 +0,0 @@
import {
calculateCurrentA,
calculateDemandPowerKw,
calculateInstalledPowerKw,
} from "../calculations/power-calculation.js";
import type { Consumer } from "../models/consumer.model.js";
export interface ConsumerWithCalculatedValues extends Consumer {
installedPowerKw: number;
demandPowerKw: number;
effectiveVoltageV?: number;
currentA?: number;
}
export interface ProjectVoltageDefaults {
singlePhaseVoltageV: number;
threePhaseVoltageV: number;
}
export class PowerBalanceService {
enrichConsumer(
consumer: Consumer,
projectVoltageDefaults?: ProjectVoltageDefaults
): ConsumerWithCalculatedValues {
const installedPowerKw = calculateInstalledPowerKw({
quantity: consumer.quantity,
installedPowerPerUnitKw: consumer.installedPowerPerUnitKw,
demandFactor: consumer.demandFactor,
});
const demandPowerKw = calculateDemandPowerKw({
quantity: consumer.quantity,
installedPowerPerUnitKw: consumer.installedPowerPerUnitKw,
demandFactor: consumer.demandFactor,
});
const effectiveVoltageV =
consumer.voltageV ??
(consumer.phaseCount === 1
? projectVoltageDefaults?.singlePhaseVoltageV
: consumer.phaseCount === 3
? projectVoltageDefaults?.threePhaseVoltageV
: undefined);
let currentA: number | undefined;
if (effectiveVoltageV && consumer.phaseCount && consumer.powerFactor) {
currentA = calculateCurrentA({
demandPowerKw,
voltageV: effectiveVoltageV,
phaseCount: consumer.phaseCount,
powerFactor: consumer.powerFactor,
});
}
return {
...consumer,
installedPowerKw,
demandPowerKw,
effectiveVoltageV,
currentA,
};
}
}