forked from jappel/leistungsbilanz-ts
Persist circuit structure edits
This commit is contained in:
parent
76d8d59391
commit
2eba4ea75e
19 changed files with 809 additions and 964 deletions
|
|
@ -17,10 +17,6 @@ import type {
|
|||
ProjectDto,
|
||||
RoomDto,
|
||||
CircuitTreeResponseDto,
|
||||
CircuitTreeCircuitDto,
|
||||
CircuitTreeDeviceRowDto,
|
||||
CreateCircuitInputDto,
|
||||
CreateCircuitDeviceRowInputDto,
|
||||
} from "../types";
|
||||
import type { ProjectDeviceSyncField } from "../../shared/constants/project-device-sync-fields";
|
||||
import {
|
||||
|
|
@ -31,6 +27,12 @@ import {
|
|||
createCircuitDeviceRowUpdateProjectCommand,
|
||||
type CircuitDeviceRowUpdatePatch,
|
||||
} from "../../domain/models/circuit-device-row-project-command.model";
|
||||
import type {
|
||||
CircuitDeviceRowSnapshot,
|
||||
} from "../../domain/models/circuit-device-row-structure-project-command.model";
|
||||
import type {
|
||||
CircuitSnapshot,
|
||||
} from "../../domain/models/circuit-structure-project-command.model";
|
||||
|
||||
async function request<T>(url: string, init?: RequestInit): Promise<T> {
|
||||
const response = await fetch(url, {
|
||||
|
|
@ -159,33 +161,6 @@ export function getCircuitTree(projectId: string, circuitListId: string) {
|
|||
return request<CircuitTreeResponseDto>(`/api/projects/${projectId}/circuit-lists/${circuitListId}/tree`);
|
||||
}
|
||||
|
||||
export function createCircuit(projectId: string, circuitListId: string, input: CreateCircuitInputDto) {
|
||||
return request(`/api/projects/${projectId}/circuit-lists/${circuitListId}/circuits`, {
|
||||
method: "POST",
|
||||
body: JSON.stringify(input),
|
||||
});
|
||||
}
|
||||
|
||||
export function createCircuitWithDeviceRows(
|
||||
projectId: string,
|
||||
circuitListId: string,
|
||||
input: {
|
||||
circuit: CreateCircuitInputDto;
|
||||
deviceRows: CreateCircuitDeviceRowInputDto[];
|
||||
}
|
||||
) {
|
||||
return request<{
|
||||
circuit: CircuitTreeCircuitDto;
|
||||
deviceRows: CircuitTreeDeviceRowDto[];
|
||||
}>(
|
||||
`/api/projects/${projectId}/circuit-lists/${circuitListId}/circuits-with-device-rows`,
|
||||
{
|
||||
method: "POST",
|
||||
body: JSON.stringify(input),
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
export function updateCircuitById(
|
||||
projectId: string,
|
||||
expectedRevision: number,
|
||||
|
|
@ -200,6 +175,43 @@ export function updateCircuitById(
|
|||
);
|
||||
}
|
||||
|
||||
export function insertCircuitCommand(
|
||||
projectId: string,
|
||||
expectedRevision: number,
|
||||
circuit: CircuitSnapshot,
|
||||
description: string
|
||||
) {
|
||||
return executeProjectCommand(
|
||||
projectId,
|
||||
expectedRevision,
|
||||
{
|
||||
schemaVersion: 1,
|
||||
type: "circuit.insert",
|
||||
payload: { circuit },
|
||||
},
|
||||
description
|
||||
);
|
||||
}
|
||||
|
||||
export function deleteCircuitCommand(
|
||||
projectId: string,
|
||||
expectedRevision: number,
|
||||
circuitId: string,
|
||||
expectedCircuitListId: string,
|
||||
description: string
|
||||
) {
|
||||
return executeProjectCommand(
|
||||
projectId,
|
||||
expectedRevision,
|
||||
{
|
||||
schemaVersion: 1,
|
||||
type: "circuit.delete",
|
||||
payload: { circuitId, expectedCircuitListId },
|
||||
},
|
||||
description
|
||||
);
|
||||
}
|
||||
|
||||
export function deleteCircuitById(circuitId: string) {
|
||||
return request<void>(`/api/circuits/${circuitId}`, {
|
||||
method: "DELETE",
|
||||
|
|
@ -212,13 +224,6 @@ export function getNextCircuitIdentifier(sectionId: string) {
|
|||
);
|
||||
}
|
||||
|
||||
export function createCircuitDeviceRow(circuitId: string, input: CreateCircuitDeviceRowInputDto) {
|
||||
return request(`/api/circuits/${circuitId}/device-rows`, {
|
||||
method: "POST",
|
||||
body: JSON.stringify(input),
|
||||
});
|
||||
}
|
||||
|
||||
export function updateCircuitDeviceRowById(
|
||||
projectId: string,
|
||||
expectedRevision: number,
|
||||
|
|
@ -233,10 +238,41 @@ export function updateCircuitDeviceRowById(
|
|||
);
|
||||
}
|
||||
|
||||
export function deleteCircuitDeviceRowById(rowId: string) {
|
||||
return request<void>(`/api/circuit-device-rows/${rowId}`, {
|
||||
method: "DELETE",
|
||||
});
|
||||
export function insertCircuitDeviceRowCommand(
|
||||
projectId: string,
|
||||
expectedRevision: number,
|
||||
row: CircuitDeviceRowSnapshot,
|
||||
description: string
|
||||
) {
|
||||
return executeProjectCommand(
|
||||
projectId,
|
||||
expectedRevision,
|
||||
{
|
||||
schemaVersion: 1,
|
||||
type: "circuit-device-row.insert",
|
||||
payload: { row },
|
||||
},
|
||||
description
|
||||
);
|
||||
}
|
||||
|
||||
export function deleteCircuitDeviceRowCommand(
|
||||
projectId: string,
|
||||
expectedRevision: number,
|
||||
rowId: string,
|
||||
expectedCircuitId: string,
|
||||
description: string
|
||||
) {
|
||||
return executeProjectCommand(
|
||||
projectId,
|
||||
expectedRevision,
|
||||
{
|
||||
schemaVersion: 1,
|
||||
type: "circuit-device-row.delete",
|
||||
payload: { rowId, expectedCircuitId },
|
||||
},
|
||||
description
|
||||
);
|
||||
}
|
||||
|
||||
export function moveCircuitDeviceRowById(
|
||||
|
|
|
|||
73
src/frontend/utils/circuit-structure-command.ts
Normal file
73
src/frontend/utils/circuit-structure-command.ts
Normal file
|
|
@ -0,0 +1,73 @@
|
|||
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";
|
||||
|
||||
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,
|
||||
legacyConsumerId: 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[];
|
||||
}): CircuitSnapshot {
|
||||
const { id, circuitListId, values, deviceRows } = input;
|
||||
return {
|
||||
id,
|
||||
circuitListId,
|
||||
sectionId: values.sectionId,
|
||||
equipmentIdentifier: values.equipmentIdentifier,
|
||||
displayName: values.displayName ?? null,
|
||||
sortOrder: values.sortOrder,
|
||||
protectionType: values.protectionType ?? null,
|
||||
protectionRatedCurrent: values.protectionRatedCurrent ?? null,
|
||||
protectionCharacteristic: values.protectionCharacteristic ?? null,
|
||||
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,
|
||||
};
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue