Add name and date columns to sharedAdventures table and display them in shared adventure page
This commit is contained in:
@@ -16,6 +16,8 @@ export const featuredAdventures = pgTable("featuredAdventures", {
|
||||
export const sharedAdventures = pgTable("sharedAdventures", {
|
||||
id: text("id").primaryKey(),
|
||||
data: json("data").notNull(),
|
||||
name: text("name").notNull(),
|
||||
date: text("date").notNull(),
|
||||
});
|
||||
|
||||
export const userTable = pgTable("user", {
|
||||
|
||||
@@ -2,13 +2,15 @@ import { db } from "$lib/db/db.server";
|
||||
import { sharedAdventures } from "$lib/db/schema";
|
||||
import type { Adventure } from "$lib/utils/types";
|
||||
|
||||
export async function POST({ request }: { request: Request }) {
|
||||
export async function POST({ request, locals }) {
|
||||
const { key, data } = await request.json();
|
||||
let adventure = data as Adventure;
|
||||
console.log(adventure);
|
||||
let date = new Date().toISOString().split("T")[0];
|
||||
let name = locals.user ? locals.user.username : "Anonymous";
|
||||
await db
|
||||
.insert(sharedAdventures)
|
||||
.values({ id: key, data: adventure })
|
||||
.values({ id: key, data: adventure, name:name, date:date })
|
||||
.execute();
|
||||
return new Response(JSON.stringify({ key: key }));
|
||||
}
|
||||
}
|
||||
@@ -29,9 +29,14 @@ export async function load({ params }) {
|
||||
} as Adventure;
|
||||
});
|
||||
|
||||
let name = rawData.name;
|
||||
let date = rawData.date;
|
||||
|
||||
|
||||
// Return the array of Adventure objects
|
||||
return {
|
||||
adventureArray,
|
||||
name,
|
||||
date,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
</div>
|
||||
{/each} -->
|
||||
<h1 class="text-center font-bold text-4xl">Shared Adventure List</h1>
|
||||
<h2 class="text-center text-2xl">By {data.name} on {data.date}</h2>
|
||||
<div
|
||||
class="grid xl:grid-cols-3 lg:grid-cols-3 md:grid-cols-2 sm:grid-cols-1 gap-4 mt-4 content-center auto-cols-auto ml-6 mr-6"
|
||||
>
|
||||
|
||||
Reference in New Issue
Block a user