Configure circuit protection
This commit is contained in:
@@ -17,6 +17,7 @@ import type {
|
||||
import type { AppDatabase } from "../database-context.js";
|
||||
import { circuitDeviceRows } from "../schema/circuit-device-rows.js";
|
||||
import { circuitLists } from "../schema/circuit-lists.js";
|
||||
import { circuitProtectionDevices } from "../schema/circuit-protection-devices.js";
|
||||
import { circuitSections } from "../schema/circuit-sections.js";
|
||||
import { circuits } from "../schema/circuits.js";
|
||||
import { executeProjectCommandTransaction } from "./project-command-transaction.persistence.js";
|
||||
@@ -396,6 +397,12 @@ export class CircuitDeviceRowMoveProjectCommandRepository
|
||||
remark: snapshot.remark,
|
||||
})
|
||||
.run();
|
||||
if (snapshot.protectionDevice) {
|
||||
database
|
||||
.insert(circuitProtectionDevices)
|
||||
.values(snapshot.protectionDevice)
|
||||
.run();
|
||||
}
|
||||
}
|
||||
|
||||
private assertTargetCircuitUnchanged(
|
||||
@@ -438,6 +445,27 @@ export class CircuitDeviceRowMoveProjectCommandRepository
|
||||
"Created target circuit changed before command execution."
|
||||
);
|
||||
}
|
||||
const protectionDevice = database
|
||||
.select()
|
||||
.from(circuitProtectionDevices)
|
||||
.where(eq(circuitProtectionDevices.circuitId, snapshot.id))
|
||||
.get();
|
||||
if (
|
||||
snapshot.protectionDevice === undefined
|
||||
? protectionDevice !== undefined
|
||||
: snapshot.protectionDevice === null
|
||||
? protectionDevice !== undefined
|
||||
: !protectionDevice ||
|
||||
Object.entries(snapshot.protectionDevice).some(
|
||||
([key, value]) =>
|
||||
(protectionDevice as Record<string, unknown>)[key] !==
|
||||
value
|
||||
)
|
||||
) {
|
||||
throw new Error(
|
||||
"Created target circuit protection changed before command execution."
|
||||
);
|
||||
}
|
||||
|
||||
const currentRowIds = database
|
||||
.select({ id: circuitDeviceRows.id })
|
||||
|
||||
Reference in New Issue
Block a user