diff --git a/src/lib/components/CreateNewAdventure.svelte b/src/lib/components/CreateNewAdventure.svelte index 579b6eb..25a0ec9 100644 --- a/src/lib/components/CreateNewAdventure.svelte +++ b/src/lib/components/CreateNewAdventure.svelte @@ -46,10 +46,7 @@ const activities = activityInput .split(" ") .filter((activity) => activity.trim() !== ""); - newAdventure.activityTypes = [ - ...(newAdventure.activityTypes || []), - ...activities, - ]; + newAdventure.activityTypes = activities; activityInput = ""; } console.log(newAdventure.activityTypes); @@ -104,7 +101,7 @@ />
- +
+
+ + +
diff --git a/src/routes/api/visits/+server.ts b/src/routes/api/visits/+server.ts index ce2c654..3afa6ba 100644 --- a/src/routes/api/visits/+server.ts +++ b/src/routes/api/visits/+server.ts @@ -103,7 +103,7 @@ export async function POST(event: RequestEvent): Promise { }); } - const { name, location, date, description, activityTypes } = + const { name, location, date, description, activityTypes, rating } = body.detailAdventure; if (!name) { @@ -112,6 +112,12 @@ export async function POST(event: RequestEvent): Promise { }); } + if (rating && (rating < 1 || rating > 5)) { + return error(400, { + message: "Rating must be between 1 and 5", + }); + } + console.log(activityTypes); // insert the adventure to the user's visited list @@ -125,6 +131,7 @@ export async function POST(event: RequestEvent): Promise { date: date || null, description: description || null, activityTypes: JSON.stringify(activityTypes) || null, + rating: rating || null, }) .returning({ insertedId: adventureTable.id }) .execute(); @@ -168,7 +175,7 @@ export async function PUT(event: RequestEvent): Promise { }); } - const { name, location, date, description, activityTypes, id } = + const { name, location, date, description, activityTypes, id, rating } = body.detailAdventure; if (!name) { @@ -185,6 +192,7 @@ export async function PUT(event: RequestEvent): Promise { location: location, date: date, description: description, + rating: rating, activityTypes: JSON.stringify(activityTypes), }) .where( diff --git a/src/routes/featured/+page.svelte b/src/routes/featured/+page.svelte index 8d0cd46..176392e 100644 --- a/src/routes/featured/+page.svelte +++ b/src/routes/featured/+page.svelte @@ -11,12 +11,7 @@ }); async function add(event: CustomEvent) { - let newAdventure: Adventure = { - name: event.detail.name, - location: event.detail.location, - type: "mylog", - id: -1, - }; + let detailAdventure = event.detail; const response = await fetch("/api/visits", { method: "POST", @@ -24,7 +19,7 @@ "Content-Type": "application/json", }, body: JSON.stringify({ - newAdventure, + detailAdventure, }), });