forked from jappel/leistungsbilanz-ts
24 lines
689 B
TypeScript
24 lines
689 B
TypeScript
import { and, asc, eq } from "drizzle-orm";
|
|
import type { AppDatabase } from "../database-context.js";
|
|
import { floors } from "../schema/floors.js";
|
|
|
|
export class FloorRepository {
|
|
constructor(private readonly database: AppDatabase) {}
|
|
|
|
async listByProject(projectId: string) {
|
|
const db = this.database;
|
|
return db
|
|
.select()
|
|
.from(floors)
|
|
.where(eq(floors.projectId, projectId))
|
|
.orderBy(asc(floors.sortOrder), asc(floors.name));
|
|
}
|
|
|
|
async findById(projectId: string, floorId: string) {
|
|
return this.database
|
|
.select()
|
|
.from(floors)
|
|
.where(and(eq(floors.projectId, projectId), eq(floors.id, floorId)))
|
|
.get() ?? null;
|
|
}
|
|
}
|