routing for floors

This commit is contained in:
David Senoner 2025-05-18 23:58:46 +02:00
parent 645990bb86
commit 52539d891e
4 changed files with 14 additions and 8 deletions

View file

@ -4,9 +4,7 @@ import { fail } from "@sveltejs/kit";
import { eq } from "drizzle-orm";
export const load = async (event) => {
const floors = await db.select().from(table.floors).orderBy(table.floors.floor);
return { floors: floors };
return {};
};
export const actions = {
@ -19,10 +17,8 @@ export const actions = {
const exists = await db
.select({ floor: table.floors.floor })
.from(table.floors)
.where(eq(table.floors.floor, n))
.execute();
console.log(n);
console.log(exists);
.where(eq(table.floors.floor, n));
if (exists.length == 1) return fail(400, { message: "Floor " + n + " already exists!" });
await db.insert(table.floors).values({ floor: n, url: "/" });