forked from jappel/leistungsbilanz-ts
Add proposed cable-sizing module
Isolated module (mirrors src/external-model/ dependency direction) that adds an on-demand, DIN VDE 0298-4 referenced cable cross-section calculator: a click-on-a-circuit input mask for laying method, insulation, ambient temperature, grouping and voltage-drop limit that suggests a cross-section for the circuit cableCrossSection/cableLength fields. Applying a suggestion goes through the existing circuit.update command (expectedRevision, undo/redo) unchanged - nothing here writes to circuits directly or touches the revision/command system. See docs/cable-sizing-module.md for the full rationale, API contract, verification status and maintenance plan. Proposal, not yet reviewed by the project owner - see the docs file. 423 existing + 11 new tests pass, build:api/build:web/typecheck:scripts clean.
This commit is contained in:
parent
a17e2e3f4b
commit
1d030971dd
17 changed files with 4179 additions and 2 deletions
37
src/db/repositories/cable-sizing-calculation.repository.ts
Normal file
37
src/db/repositories/cable-sizing-calculation.repository.ts
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
import { desc, eq } from "drizzle-orm";
|
||||
import type { AppDatabase } from "../database-context.js";
|
||||
import {
|
||||
cableSizingCalculations,
|
||||
type CableSizingCalculation,
|
||||
type NewCableSizingCalculation,
|
||||
} from "../schema/cable-sizing-calculations.js";
|
||||
|
||||
// Plain repository, no revision/command semantics - mirrors
|
||||
// application-repositories.ts's flat repository pattern, not the
|
||||
// project-command-transaction boundary. A calculation is an audit record,
|
||||
// not a project mutation.
|
||||
export class CableSizingCalculationRepository {
|
||||
constructor(private readonly db: AppDatabase) {}
|
||||
|
||||
create(input: NewCableSizingCalculation): CableSizingCalculation {
|
||||
return this.db.insert(cableSizingCalculations).values(input).returning().get();
|
||||
}
|
||||
|
||||
listByCircuit(circuitId: string): CableSizingCalculation[] {
|
||||
return this.db
|
||||
.select()
|
||||
.from(cableSizingCalculations)
|
||||
.where(eq(cableSizingCalculations.circuitId, circuitId))
|
||||
.orderBy(desc(cableSizingCalculations.createdAt))
|
||||
.all();
|
||||
}
|
||||
|
||||
markApplied(id: string): CableSizingCalculation | undefined {
|
||||
return this.db
|
||||
.update(cableSizingCalculations)
|
||||
.set({ appliedToCircuit: 1 })
|
||||
.where(eq(cableSizingCalculations.id, id))
|
||||
.returning()
|
||||
.get();
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue