Skip to content

Commit

Permalink
change User endpoint to allow changing of active trip
Browse files Browse the repository at this point in the history
  • Loading branch information
derGraph committed Sep 8, 2024
1 parent 0f6daed commit 1c244b4
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion src/routes/api/User/+server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ export async function PUT(event) {
let unparsedDateOfBirth = null;
let dateOfBirth = null;
let description = null;
let activeTrip = null;

if (event.locals.user?.username) {
let username = event.locals.user?.username;
Expand All @@ -89,6 +90,7 @@ export async function PUT(event) {
lastName = event.url.searchParams.get('lastName');
unparsedDateOfBirth = event.url.searchParams.get('dateOfBirth');
description = event.url.searchParams.get('description');
activeTrip = event.url.searchParams.get('activeTrip');

if (
firstName != null &&
Expand Down Expand Up @@ -125,6 +127,20 @@ export async function PUT(event) {
} catch (error_message) {
error(400, { message: 'Invalid Date of Birth!' });
}

try {
if(activeTrip){
await prisma.trip.findFirstOrThrow({
where: {
id: activeTrip,
skipperName: username
}
});
}
} catch (error_message) {
error(400, {message: 'Invalid activeTrip! Only the skipper can choose a trip as active!'});
}

await prisma.user.update({
where: {
username: username
Expand All @@ -133,7 +149,8 @@ export async function PUT(event) {
...(dateOfBirth && { dateOfBirth }),
...(firstName && { firstName }),
...(lastName && { lastName }),
...(description && { description })
...(description && { description }),
...(activeTrip && {activeTrip:{connect:{id:activeTrip}}})
}
});
return new Response('200');
Expand Down

0 comments on commit 1c244b4

Please sign in to comment.