Persist project locations

This commit is contained in:
2026-07-26 10:56:29 +02:00
parent 1cf26a932e
commit ac465a1cc0
23 changed files with 1313 additions and 101 deletions
+1 -30
View File
@@ -1,8 +1,6 @@
import crypto from "node:crypto";
import { and, asc, eq } from "drizzle-orm";
import { asc, eq } from "drizzle-orm";
import { db } from "../client.js";
import { rooms } from "../schema/rooms.js";
import type { CreateRoomInput } from "../../shared/validation/project-structure.schemas.js";
export class RoomRepository {
async listByProject(projectId: string) {
@@ -12,31 +10,4 @@ export class RoomRepository {
.where(eq(rooms.projectId, projectId))
.orderBy(asc(rooms.roomNumber), asc(rooms.roomName));
}
async create(projectId: string, input: CreateRoomInput) {
const id = crypto.randomUUID();
const room = {
id,
projectId,
floorId: input.floorId ?? null,
roomNumber: input.roomNumber,
roomName: input.roomName,
};
await db.insert(rooms).values(room);
return room;
}
async existsInProject(projectId: string, roomId: string) {
const [row] = await db
.select({ id: rooms.id })
.from(rooms)
.where(and(eq(rooms.projectId, projectId), eq(rooms.id, roomId)))
.limit(1);
return Boolean(row);
}
async findById(roomId: string) {
const [row] = await db.select().from(rooms).where(eq(rooms.id, roomId)).limit(1);
return row ?? null;
}
}