show floors in descending order
This commit is contained in:
parent
e3b9a83e73
commit
cab2b67227
4 changed files with 48 additions and 40 deletions
|
@ -1,6 +1,7 @@
|
|||
import { db } from "$lib/server/db";
|
||||
import * as table from "$lib/server/db/schema";
|
||||
import { redirect } from "@sveltejs/kit";
|
||||
import { desc } from "drizzle-orm";
|
||||
|
||||
export const load = async (event) => {
|
||||
if (!event.locals.user) {
|
||||
|
@ -9,6 +10,6 @@ export const load = async (event) => {
|
|||
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);
|
||||
const floors = await db.select().from(table.floors).orderBy(desc(table.floors.floor));
|
||||
return { user: event.locals.user, floors: floors };
|
||||
};
|
||||
|
|
|
@ -1,36 +1,36 @@
|
|||
import { db } from "$lib/server/db";
|
||||
import * as table from "$lib/server/db/schema";
|
||||
import { eq } from "drizzle-orm";
|
||||
import type { PageServerLoad } from "./$types";
|
||||
|
||||
export const load: PageServerLoad = async ({ params }) => {
|
||||
{
|
||||
const floor = await db.select({ floor: table.plans.floor, json: table.plans.plan }).from(table.plans);
|
||||
if (floor.length == 0) {
|
||||
await db.insert(table.plans).values({ floor: params.slug, plan: {
|
||||
"regions": [
|
||||
{ "start": { "x": 100, "y": 100 }, "end": { "x": 400, "y": 100 } },
|
||||
{ "start": { "x": 400, "y": 100 }, "end": { "x": 400, "y": 300 } },
|
||||
{ "start": { "x": 400, "y": 300 }, "end": { "x": 100, "y": 300 } },
|
||||
{ "start": { "x": 100, "y": 300 }, "end": { "x": 100, "y": 100 } }
|
||||
],
|
||||
"doors": [
|
||||
{ "location": { "x": 240, "y": 100 }, "width": 50, "rotation": 0 }
|
||||
],
|
||||
"furnitures": [
|
||||
{
|
||||
"minBound": { "x": 150, "y": 150 },
|
||||
"maxBound": { "x": 200, "y": 200 },
|
||||
"equipName": "Table",
|
||||
"xPlacement": 150,
|
||||
"yPlacement": 150,
|
||||
"rotation": 0
|
||||
}
|
||||
]
|
||||
}
|
||||
});
|
||||
const floor_cnt = await db.select({ floor: table.plans.floor, json: table.plans.plan }).from(table.plans).where(eq(table.plans.floor, params.slug));
|
||||
if (floor_cnt.length == 0) {
|
||||
await db.insert(table.plans).values({ floor: params.slug, plan: {
|
||||
"regions": [
|
||||
{ "start": { "x": 100, "y": 100 }, "end": { "x": 400, "y": 100 } },
|
||||
{ "start": { "x": 400, "y": 100 }, "end": { "x": 400, "y": 300 } },
|
||||
{ "start": { "x": 400, "y": 300 }, "end": { "x": 100, "y": 300 } },
|
||||
{ "start": { "x": 100, "y": 300 }, "end": { "x": 100, "y": 100 } }
|
||||
],
|
||||
"doors": [
|
||||
{ "location": { "x": 240, "y": 100 }, "width": 50, "rotation": 0 }
|
||||
],
|
||||
"furnitures": [
|
||||
{
|
||||
"minBound": { "x": 150, "y": 150 },
|
||||
"maxBound": { "x": 200, "y": 200 },
|
||||
"equipName": "Table",
|
||||
"xPlacement": 150,
|
||||
"yPlacement": 150,
|
||||
"rotation": 0
|
||||
}
|
||||
]
|
||||
}});
|
||||
}
|
||||
|
||||
}
|
||||
const floor = await db.select({ floor: table.plans.floor, json: table.plans.plan }).from(table.plans);
|
||||
return { slug: params.slug, floor: floor };
|
||||
const floor_ = await db.select({ floor: table.plans.floor, json: table.plans.plan }).from(table.plans).where(eq(table.plans.floor, params.slug));
|
||||
return { slug: params.slug, floor: floor_ };
|
||||
};
|
||||
|
|
|
@ -32,6 +32,13 @@ export const actions = {
|
|||
const floors = await db.select().from(table.floors);
|
||||
if (floors.length == 1) return fail(400, { message: "Cannot delete last floor!" });
|
||||
|
||||
const exists = await db
|
||||
.select({ floor: table.floors.floor })
|
||||
.from(table.floors)
|
||||
.where(eq(table.floors.floor, n));
|
||||
|
||||
if (exists.length == 0) return fail(400, { message: "Floor " + n + " does not exist!" });
|
||||
|
||||
await db.delete(table.floors).where(eq(table.floors.floor, n));
|
||||
},
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue