Inject application database contexts

This commit is contained in:
2026-07-26 12:30:42 +02:00
parent 859fa4a42a
commit d7b98de56a
26 changed files with 201 additions and 63 deletions
@@ -1,5 +1,5 @@
import { and, eq } from "drizzle-orm";
import { db } from "../client.js";
import type { AppDatabase } from "../database-context.js";
import { projectDevices } from "../schema/project-devices.js";
import { calculateRowTotalPower } from "../../domain/calculations/circuit-power-calculation.js";
@@ -11,12 +11,16 @@ function withTotalPower(row: typeof projectDevices.$inferSelect) {
}
export class ProjectDeviceRepository {
constructor(private readonly database: AppDatabase) {}
async listByProject(projectId: string) {
const db = this.database;
const rows = await db.select().from(projectDevices).where(eq(projectDevices.projectId, projectId));
return rows.map(withTotalPower);
}
async findById(projectId: string, projectDeviceId: string) {
const db = this.database;
const [row] = await db
.select()
.from(projectDevices)