feat: edit page
This commit is contained in:
46
src/routes/space/[id]/edit/+page.server.ts
Normal file
46
src/routes/space/[id]/edit/+page.server.ts
Normal file
@@ -0,0 +1,46 @@
|
||||
import { error } from "@sveltejs/kit";
|
||||
import type { PageServerLoad } from "./$types";
|
||||
import type { Table } from "$lib";
|
||||
|
||||
type StudySpaceData = Omit<
|
||||
Table<"study_spaces">,
|
||||
"id" | "created_at" | "updated_at" | "building_location_old" | "building_location"
|
||||
> & {
|
||||
id?: string;
|
||||
building_location?: google.maps.places.PlaceResult;
|
||||
};
|
||||
|
||||
export const load: PageServerLoad = async ({ params, locals: { supabase } }) => {
|
||||
if (params.id === "new") {
|
||||
return {
|
||||
space: {
|
||||
description: "",
|
||||
building_location: undefined,
|
||||
location: "",
|
||||
tags: [],
|
||||
volume: "",
|
||||
power: "",
|
||||
wifi: ""
|
||||
} as StudySpaceData
|
||||
};
|
||||
}
|
||||
|
||||
const { data: space, error: err } = await supabase
|
||||
.from("study_spaces")
|
||||
.select("*, study_space_images(*)")
|
||||
.eq("id", params.id)
|
||||
.single();
|
||||
if (err) error(500, "Failed to load study space");
|
||||
const studySpaceData = space as StudySpaceData & Partial<typeof space>;
|
||||
|
||||
const images = studySpaceData.study_space_images || [];
|
||||
|
||||
delete studySpaceData.created_at;
|
||||
delete studySpaceData.updated_at;
|
||||
delete studySpaceData.study_space_images;
|
||||
|
||||
return {
|
||||
space: studySpaceData as StudySpaceData,
|
||||
images
|
||||
};
|
||||
};
|
||||
Reference in New Issue
Block a user