handle floor 0 case

This commit is contained in:
David Senoner 2025-05-18 19:07:41 +02:00
parent b0ffcb838f
commit 645990bb86
3 changed files with 6 additions and 3 deletions

View file

@ -1,6 +1,6 @@
services:
db:
image: postgis/postgis:17-3.5-alpine
image: postgres:17.5-alpine3.20
restart: always
ports:
- 5432:5432

View file

@ -6,7 +6,9 @@ export const load = async (event) => {
if (!event.locals.user) {
return redirect(302, "/login");
}
const floors = await db.select().from(table.floors).orderBy(table.floors.floor);
const floors_length = (await db.select().from(table.floors).orderBy(table.floors.floor)).length;
if (floors_length == 0) await db.insert(table.floors).values({ floor: 0, url: "/" });
const floors = await db.select().from(table.floors).orderBy(table.floors.floor);
return { user: event.locals.user, floors: floors };
};

View file

@ -11,6 +11,8 @@
function getFloorName(n) {
switch (n) {
case 0:
return "Ground floor";
case 1:
return "1st floor";
case 2:
@ -21,7 +23,6 @@
return n + "th floor";
}
}
console.log(data.floors);
</script>
<Sidebar.Provider>