Add new columns to userPlannedAdventures table and update Adventure interface

This commit is contained in:
Sean Morley
2024-04-21 22:56:27 +00:00
parent b2184bdee3
commit a3d4d757a9
16 changed files with 548 additions and 43 deletions

View File

@@ -26,7 +26,7 @@ export async function GET(event: RequestEvent): Promise<Response> {
id: item.adventureID,
name: item.adventureName,
location: item.location,
created: item.visitedDate,
date: item.visitedDate,
})),
}),
{
@@ -91,7 +91,7 @@ export async function POST(event: RequestEvent): Promise<Response> {
}
// get properties from the body
const { name, location, created } = await event.request.json();
const { name, location, date } = await event.request.json();
// insert the adventure to the user's visited list
await db
@@ -100,10 +100,10 @@ export async function POST(event: RequestEvent): Promise<Response> {
userId: event.locals.user.id,
adventureName: name,
location: location,
visitedDate: created,
visitedDate: date,
})
.execute();
let res = await db
let res = await db
.select()
.from(userVisitedAdventures)
.where(
@@ -111,17 +111,17 @@ let res = await db
eq(userVisitedAdventures.userId, event.locals.user.id),
eq(userVisitedAdventures.adventureName, name),
eq(userVisitedAdventures.location, location),
eq(userVisitedAdventures.visitedDate, created)
eq(userVisitedAdventures.visitedDate, date)
)
)
.execute();
// return a response with the adventure object values
// return a response with the adventure object values
return new Response(
JSON.stringify({
adventure: { name, location, created },
adventure: { name, location, date },
message: { message: "Adventure added" },
id: res[0].adventureID
id: res[0].adventureID,
}),
{
status: 200,
@@ -144,7 +144,7 @@ export async function PUT(event: RequestEvent): Promise<Response> {
}
// get properties from the body
const { id, name, location, created } = await event.request.json();
const { id, name, location, date } = await event.request.json();
// update the adventure in the user's visited list
await db
@@ -152,7 +152,7 @@ export async function PUT(event: RequestEvent): Promise<Response> {
.set({
adventureName: name,
location: location,
visitedDate: created,
visitedDate: date,
})
.where(
and(
@@ -164,7 +164,7 @@ export async function PUT(event: RequestEvent): Promise<Response> {
return new Response(
JSON.stringify({
adventure: { id, name, location, created },
adventure: { id, name, location, date },
message: { message: "Adventure updated" },
}),
{
@@ -174,4 +174,4 @@ export async function PUT(event: RequestEvent): Promise<Response> {
},
}
);
}
}

View File

@@ -19,7 +19,7 @@
body: JSON.stringify({
name: event.detail.name,
location: event.detail.location,
created: "",
date: "",
}),
});
@@ -46,7 +46,7 @@
on:add={add}
name={adventure.name}
location={adventure.location}
created=""
date=""
id={NaN}
/>
{/each}

View File

@@ -20,7 +20,7 @@
let editId: number = NaN;
let editName: string = "";
let editLocation: string = "";
let editCreated: string = "";
let editdate: string = "";
let isShowingToast: boolean = false;
let toastAction: string = "";
@@ -71,7 +71,7 @@
body: JSON.stringify({
name: newName,
location: newLocation,
created: dateString,
date: dateString,
}),
})
.then((response) => response.json())
@@ -84,7 +84,7 @@
id: newId,
name: newName,
location: newLocation,
created: dateString,
date: dateString,
},
];
newName = ""; // Reset newName and newLocation after adding adventure
@@ -109,7 +109,7 @@
id: event.detail.id,
name: event.detail.name,
location: event.detail.location,
created: event.detail.created,
date: event.detail.date,
}),
})
.then((response) => response.json())
@@ -122,7 +122,7 @@
editId = NaN;
editName = "";
editLocation = "";
editCreated = "";
editdate = "";
showToast("Adventure edited successfully!");
})
.catch((error) => {
@@ -138,7 +138,7 @@
editId = adventure.id || 0;
editName = adventure.name || "";
editLocation = adventure.location || "";
editCreated = adventure.created || "";
editdate = adventure.date || "";
}
}
@@ -168,7 +168,7 @@
editId = NaN;
editName = "";
editLocation = "";
editCreated = "";
editdate = "";
}
function deleteData() {
@@ -263,7 +263,7 @@
bind:editId
bind:editName
bind:editLocation
bind:editCreated
bind:editdate
on:submit={saveAdventure}
on:close={handleClose}
/>
@@ -278,7 +278,7 @@
id={adventure.id}
name={adventure.name}
location={adventure.location}
created={adventure.created}
date={adventure.date}
on:edit={editAdventure}
on:remove={removeAdventure}
/>

View File

@@ -24,6 +24,8 @@
name={adventure.name}
location={adventure.location}
activityTypes={adventure.activityTypes}
description={adventure?.description}
date={adventure?.date}
/>
{/each}
</div>

View File

@@ -25,14 +25,13 @@ export async function load({ params }) {
id: item.id,
name: item.name,
location: item.location,
created: item.created,
date: item.date,
} as Adventure;
});
let name = rawData.name;
let date = rawData.date;
// Return the array of Adventure objects
return {
adventureArray,

View File

@@ -10,7 +10,7 @@
<div>
<h1>{adventure.name}</h1>
<p>{adventure.location}</p>
<p>{adventure.created}</p>
<p>{adventure.date}</p>
<p>{adventure.id}</p>
</div>
{/each} -->
@@ -25,7 +25,7 @@
id={adventure.id}
name={adventure.name}
location={adventure.location}
created={adventure.created}
date={adventure.date}
/>
{/each}
</div>

View File

@@ -129,7 +129,7 @@ export const actions: Actions = {
"content-type": "application/json",
},
body: JSON.stringify({
message: "User created",
message: "User date",
}),
};
}