Rewrite frontend, added rooms, voltage selection per project, startet with todos
This commit is contained in:
@@ -1,14 +1,34 @@
|
||||
export interface ProjectDto {
|
||||
id: string;
|
||||
name: string;
|
||||
singlePhaseVoltageV: number;
|
||||
threePhaseVoltageV: number;
|
||||
}
|
||||
|
||||
export interface ConsumerWithCalculatedValues {
|
||||
id: string;
|
||||
projectId: string;
|
||||
distributionBoardId?: string | null;
|
||||
circuitListId?: string | null;
|
||||
roomId?: string | null;
|
||||
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;
|
||||
@@ -18,6 +38,7 @@ export interface ConsumerWithCalculatedValues {
|
||||
note?: string;
|
||||
installedPowerKw: number;
|
||||
demandPowerKw: number;
|
||||
effectiveVoltageV?: number;
|
||||
currentA?: number;
|
||||
}
|
||||
|
||||
@@ -27,11 +48,74 @@ export interface DistributionBoardDto {
|
||||
name: string;
|
||||
}
|
||||
|
||||
export interface CircuitListDto {
|
||||
id: string;
|
||||
projectId: string;
|
||||
distributionBoardId: string;
|
||||
name: string;
|
||||
}
|
||||
|
||||
export interface FloorDto {
|
||||
id: string;
|
||||
projectId: string;
|
||||
name: string;
|
||||
sortOrder: number;
|
||||
}
|
||||
|
||||
export interface RoomDto {
|
||||
id: string;
|
||||
projectId: string;
|
||||
floorId: string | null;
|
||||
roomNumber: string;
|
||||
roomName: string;
|
||||
}
|
||||
|
||||
export interface GlobalDeviceDto {
|
||||
id: string;
|
||||
name: string;
|
||||
category: string | null;
|
||||
quantity: number;
|
||||
installedPowerPerUnitKw: number;
|
||||
demandFactor: number;
|
||||
voltageV: number | null;
|
||||
phaseCount: 1 | 3 | null;
|
||||
powerFactor: number | null;
|
||||
note: string | null;
|
||||
}
|
||||
|
||||
export interface ProjectDeviceDto {
|
||||
id: string;
|
||||
projectId: string;
|
||||
name: string;
|
||||
category: string | null;
|
||||
quantity: number;
|
||||
installedPowerPerUnitKw: number;
|
||||
demandFactor: number;
|
||||
voltageV: number | null;
|
||||
phaseCount: 1 | 3 | null;
|
||||
powerFactor: number | null;
|
||||
note: string | null;
|
||||
}
|
||||
|
||||
export interface CreateConsumerInput {
|
||||
projectId: string;
|
||||
distributionBoardId?: string;
|
||||
circuitListId?: string;
|
||||
roomId?: 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;
|
||||
@@ -42,3 +126,37 @@ export interface CreateConsumerInput {
|
||||
}
|
||||
|
||||
export interface UpdateConsumerInput extends CreateConsumerInput {}
|
||||
|
||||
export interface CreateFloorInput {
|
||||
name: string;
|
||||
}
|
||||
|
||||
export interface CreateRoomInput {
|
||||
floorId?: string;
|
||||
roomNumber: string;
|
||||
roomName: string;
|
||||
}
|
||||
|
||||
export interface CreateGlobalDeviceInput {
|
||||
name: string;
|
||||
category?: string;
|
||||
quantity: number;
|
||||
installedPowerPerUnitKw: number;
|
||||
demandFactor: number;
|
||||
voltageV?: number;
|
||||
phaseCount?: 1 | 3;
|
||||
powerFactor?: number;
|
||||
note?: string;
|
||||
}
|
||||
|
||||
export interface CreateProjectDeviceInput {
|
||||
name: string;
|
||||
category?: string;
|
||||
quantity: number;
|
||||
installedPowerPerUnitKw: number;
|
||||
demandFactor: number;
|
||||
voltageV?: number;
|
||||
phaseCount?: 1 | 3;
|
||||
powerFactor?: number;
|
||||
note?: string;
|
||||
}
|
||||
|
||||
+106
-6
@@ -1,8 +1,17 @@
|
||||
import type {
|
||||
CircuitListDto,
|
||||
CreateFloorInput,
|
||||
CreateProjectDeviceInput,
|
||||
CreateRoomInput,
|
||||
ConsumerWithCalculatedValues,
|
||||
CreateConsumerInput,
|
||||
CreateGlobalDeviceInput,
|
||||
DistributionBoardDto,
|
||||
FloorDto,
|
||||
GlobalDeviceDto,
|
||||
ProjectDeviceDto,
|
||||
ProjectDto,
|
||||
RoomDto,
|
||||
UpdateConsumerInput,
|
||||
} from "../types";
|
||||
|
||||
@@ -13,6 +22,7 @@ async function request<T>(url: string, init?: RequestInit): Promise<T> {
|
||||
"Content-Type": "application/json",
|
||||
...init?.headers,
|
||||
},
|
||||
cache: "no-store",
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
@@ -20,6 +30,10 @@ async function request<T>(url: string, init?: RequestInit): Promise<T> {
|
||||
throw new Error(details || `Request failed with ${response.status}`);
|
||||
}
|
||||
|
||||
if (response.status === 204) {
|
||||
return undefined as T;
|
||||
}
|
||||
|
||||
return response.json() as Promise<T>;
|
||||
}
|
||||
|
||||
@@ -27,6 +41,10 @@ export function listProjects() {
|
||||
return request<ProjectDto[]>("/api/projects");
|
||||
}
|
||||
|
||||
export function getProject(projectId: string) {
|
||||
return request<ProjectDto>(`/api/projects/${projectId}`);
|
||||
}
|
||||
|
||||
export function createProject(name: string) {
|
||||
return request<ProjectDto>("/api/projects", {
|
||||
method: "POST",
|
||||
@@ -34,6 +52,16 @@ export function createProject(name: string) {
|
||||
});
|
||||
}
|
||||
|
||||
export function updateProjectSettings(
|
||||
projectId: string,
|
||||
input: { singlePhaseVoltageV: number; threePhaseVoltageV: number }
|
||||
) {
|
||||
return request<ProjectDto>(`/api/projects/${projectId}`, {
|
||||
method: "PUT",
|
||||
body: JSON.stringify(input),
|
||||
});
|
||||
}
|
||||
|
||||
export function listDistributionBoards(projectId: string) {
|
||||
return request<DistributionBoardDto[]>(`/api/projects/${projectId}/distribution-boards`);
|
||||
}
|
||||
@@ -45,6 +73,32 @@ export function createDistributionBoard(projectId: string, name: string) {
|
||||
});
|
||||
}
|
||||
|
||||
export function listCircuitLists(projectId: string) {
|
||||
return request<CircuitListDto[]>(`/api/projects/${projectId}/circuit-lists`);
|
||||
}
|
||||
|
||||
export function listFloors(projectId: string) {
|
||||
return request<FloorDto[]>(`/api/projects/${projectId}/floors`);
|
||||
}
|
||||
|
||||
export function createFloor(projectId: string, input: CreateFloorInput) {
|
||||
return request<FloorDto>(`/api/projects/${projectId}/floors`, {
|
||||
method: "POST",
|
||||
body: JSON.stringify(input),
|
||||
});
|
||||
}
|
||||
|
||||
export function listRooms(projectId: string) {
|
||||
return request<RoomDto[]>(`/api/projects/${projectId}/rooms`);
|
||||
}
|
||||
|
||||
export function createRoom(projectId: string, input: CreateRoomInput) {
|
||||
return request<RoomDto>(`/api/projects/${projectId}/rooms`, {
|
||||
method: "POST",
|
||||
body: JSON.stringify(input),
|
||||
});
|
||||
}
|
||||
|
||||
export function listConsumers(projectId: string) {
|
||||
return request<ConsumerWithCalculatedValues[]>(`/api/consumers/projects/${projectId}`);
|
||||
}
|
||||
@@ -63,10 +117,56 @@ export function updateConsumer(consumerId: string, input: UpdateConsumerInput) {
|
||||
});
|
||||
}
|
||||
|
||||
export async function deleteConsumer(consumerId: string) {
|
||||
const response = await fetch(`/api/consumers/${consumerId}`, { method: "DELETE" });
|
||||
if (!response.ok) {
|
||||
const details = await response.text();
|
||||
throw new Error(details || `Request failed with ${response.status}`);
|
||||
}
|
||||
export function deleteConsumer(consumerId: string) {
|
||||
return request<void>(`/api/consumers/${consumerId}`, { method: "DELETE" });
|
||||
}
|
||||
|
||||
export function listGlobalDevices() {
|
||||
return request<GlobalDeviceDto[]>("/api/global-devices");
|
||||
}
|
||||
|
||||
export function createGlobalDevice(input: CreateGlobalDeviceInput) {
|
||||
return request<GlobalDeviceDto>("/api/global-devices", {
|
||||
method: "POST",
|
||||
body: JSON.stringify(input),
|
||||
});
|
||||
}
|
||||
|
||||
export function updateGlobalDevice(globalDeviceId: string, input: CreateGlobalDeviceInput) {
|
||||
return request<GlobalDeviceDto>(`/api/global-devices/${globalDeviceId}`, {
|
||||
method: "PUT",
|
||||
body: JSON.stringify(input),
|
||||
});
|
||||
}
|
||||
|
||||
export function deleteGlobalDevice(globalDeviceId: string) {
|
||||
return request<void>(`/api/global-devices/${globalDeviceId}`, { method: "DELETE" });
|
||||
}
|
||||
|
||||
export function listProjectDevices(projectId: string) {
|
||||
return request<ProjectDeviceDto[]>(`/api/project-devices/projects/${projectId}`);
|
||||
}
|
||||
|
||||
export function createProjectDevice(projectId: string, input: CreateProjectDeviceInput) {
|
||||
return request<ProjectDeviceDto>(`/api/project-devices/projects/${projectId}`, {
|
||||
method: "POST",
|
||||
body: JSON.stringify(input),
|
||||
});
|
||||
}
|
||||
|
||||
export function updateProjectDevice(
|
||||
projectId: string,
|
||||
projectDeviceId: string,
|
||||
input: CreateProjectDeviceInput
|
||||
) {
|
||||
return request<ProjectDeviceDto>(`/api/project-devices/projects/${projectId}/${projectDeviceId}`, {
|
||||
method: "PUT",
|
||||
body: JSON.stringify(input),
|
||||
});
|
||||
}
|
||||
|
||||
export function deleteProjectDevice(projectId: string, projectDeviceId: string) {
|
||||
return request<void>(`/api/project-devices/projects/${projectId}/${projectDeviceId}`, {
|
||||
method: "DELETE",
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user