feat: Add activity types functionality to CreateNewAdventure and AdventureCard components

This commit is contained in:
Sean Morley
2024-05-04 00:43:18 +00:00
parent eab7cb6087
commit 3127784632
4 changed files with 38 additions and 17 deletions

View File

@@ -103,7 +103,7 @@ export async function POST(event: RequestEvent): Promise<Response> {
});
}
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<Response> {
});
}
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<Response> {
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<Response> {
});
}
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<Response> {
location: location,
date: date,
description: description,
rating: rating,
activityTypes: JSON.stringify(activityTypes),
})
.where(