25 lines
682 B
TypeScript
25 lines
682 B
TypeScript
import { and, asc, eq } from "drizzle-orm";
|
|
import type { AppDatabase } from "../database-context.js";
|
|
import { rooms } from "../schema/rooms.js";
|
|
|
|
export class RoomRepository {
|
|
constructor(private readonly database: AppDatabase) {}
|
|
|
|
async listByProject(projectId: string) {
|
|
const db = this.database;
|
|
return db
|
|
.select()
|
|
.from(rooms)
|
|
.where(eq(rooms.projectId, projectId))
|
|
.orderBy(asc(rooms.roomNumber), asc(rooms.roomName));
|
|
}
|
|
|
|
async findById(projectId: string, roomId: string) {
|
|
return this.database
|
|
.select()
|
|
.from(rooms)
|
|
.where(and(eq(rooms.projectId, projectId), eq(rooms.id, roomId)))
|
|
.get() ?? null;
|
|
}
|
|
}
|