Add atomic circuit update commands

This commit is contained in:
2026-07-23 21:32:25 +02:00
parent b79faed320
commit 296cb0f1c4
17 changed files with 940 additions and 167 deletions
@@ -19,6 +19,26 @@ export interface CircuitCreatePersistenceInput {
isReserve?: boolean;
}
export interface CircuitPatchPersistenceInput {
sectionId?: string;
equipmentIdentifier?: string;
displayName?: string | null;
sortOrder?: number;
protectionType?: string | null;
protectionRatedCurrent?: number | null;
protectionCharacteristic?: string | null;
cableType?: string | null;
cableCrossSection?: string | null;
cableLength?: number | null;
voltage?: number | null;
controlRequirement?: string | null;
remark?: string | null;
rcdAssignment?: string | null;
terminalDesignation?: string | null;
status?: string | null;
isReserve?: boolean;
}
export function toCircuitCreateValues(id: string, input: CircuitCreatePersistenceInput) {
return {
id,
@@ -42,3 +62,41 @@ export function toCircuitCreateValues(id: string, input: CircuitCreatePersistenc
remark: input.remark ?? null,
};
}
export function toCircuitPatchValues(input: CircuitPatchPersistenceInput) {
const values: Partial<ReturnType<typeof toCircuitCreateValues>> = {};
const has = (field: keyof CircuitPatchPersistenceInput) =>
Object.prototype.hasOwnProperty.call(input, field);
if (input.sectionId !== undefined) values.sectionId = input.sectionId;
if (input.equipmentIdentifier !== undefined) {
values.equipmentIdentifier = input.equipmentIdentifier;
}
if (has("displayName")) values.displayName = input.displayName ?? null;
if (input.sortOrder !== undefined) values.sortOrder = input.sortOrder;
if (has("protectionType")) values.protectionType = input.protectionType ?? null;
if (has("protectionRatedCurrent")) {
values.protectionRatedCurrent = input.protectionRatedCurrent ?? null;
}
if (has("protectionCharacteristic")) {
values.protectionCharacteristic = input.protectionCharacteristic ?? null;
}
if (has("cableType")) values.cableType = input.cableType ?? null;
if (has("cableCrossSection")) {
values.cableCrossSection = input.cableCrossSection ?? null;
}
if (has("cableLength")) values.cableLength = input.cableLength ?? null;
if (has("rcdAssignment")) values.rcdAssignment = input.rcdAssignment ?? null;
if (has("terminalDesignation")) {
values.terminalDesignation = input.terminalDesignation ?? null;
}
if (has("voltage")) values.voltage = input.voltage ?? null;
if (has("controlRequirement")) {
values.controlRequirement = input.controlRequirement ?? null;
}
if (has("status")) values.status = input.status ?? null;
if (input.isReserve !== undefined) values.isReserve = input.isReserve ? 1 : 0;
if (has("remark")) values.remark = input.remark ?? null;
return values;
}