forked from jappel/leistungsbilanz-ts
Validate project device drop targets
This commit is contained in:
parent
b2f5ce77a5
commit
fd62bf2e15
6 changed files with 231 additions and 30 deletions
29
src/domain/services/project-device-placement.service.ts
Normal file
29
src/domain/services/project-device-placement.service.ts
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
export interface ProjectDevicePlacementSource {
|
||||
category?: string | null;
|
||||
phaseType: "single_phase" | "three_phase";
|
||||
}
|
||||
|
||||
export interface ProjectDevicePlacementSection {
|
||||
key: string;
|
||||
}
|
||||
|
||||
export type DefaultCircuitSectionKey = "lighting" | "single_phase" | "three_phase";
|
||||
|
||||
// Lighting classification takes precedence over the electrical phase because
|
||||
// lighting devices use their dedicated numbering section by default.
|
||||
export function inferProjectDeviceSectionKey(
|
||||
device: ProjectDevicePlacementSource
|
||||
): DefaultCircuitSectionKey {
|
||||
const category = (device.category ?? "").trim().toLowerCase();
|
||||
if (category.includes("light") || category.includes("beleuchtung")) {
|
||||
return "lighting";
|
||||
}
|
||||
return device.phaseType;
|
||||
}
|
||||
|
||||
export function isProjectDevicePlacementValid(
|
||||
device: ProjectDevicePlacementSource,
|
||||
section: ProjectDevicePlacementSection
|
||||
): boolean {
|
||||
return section.key === inferProjectDeviceSectionKey(device);
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue