Skip to content

Commit

Permalink
add user filter to trips
Browse files Browse the repository at this point in the history
  • Loading branch information
derGraph committed Dec 4, 2024
1 parent b1fa047 commit 6bc7397
Showing 1 changed file with 59 additions and 24 deletions.
83 changes: 59 additions & 24 deletions src/routes/api/Trips/+server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,40 +25,74 @@ export async function GET(event: {
locals: { user: { username: any}}
}) {
let deleted = false;
let username: string|null = null;
if(event.url.searchParams.get("deleted")=="true"){
deleted = true;
}
username = event.url.searchParams.get("username");
try{
let responseData;
if(event.locals.user){
responseData = await prisma.trip.findMany({
where:{
deleted: deleted,
OR: [{
crew: {
some: {
if(username == null){
responseData = await prisma.trip.findMany({
where:{
deleted: deleted,
OR: [{
crew: {
some: {
username: event.locals.user.username
}
}
},
{
skipper: {
username: event.locals.user.username
}
}
},
{
skipper: {
username: event.locals.user.username
}
},
{
visibility: 1
},
{
visibility: 2
}]
},
{
visibility: 1
include:{
crew: true,
startPoint: true,
endPoint: true
}
});
}else{
responseData = await prisma.trip.findMany({
where:{
deleted: deleted,
OR: [
{
visibility: 1,
...(username ? {
OR: [
{crew: {some: {username: username}}},
{skipper: {username: username}},
],
} : {})
},
{
visibility: 2,
...(username ? {
OR: [
{crew: {some: {username: username}}},
{skipper: {username: username}},
],
} : {})
}]
},
{
visibility: 2
}]
},
include:{
crew: true,
startPoint: true,
endPoint: true
}
});
include:{
crew: true,
startPoint: true,
endPoint: true
}
});
}
}else{
responseData = await prisma.trip.findMany({
where: {
Expand All @@ -76,6 +110,7 @@ export async function GET(event: {
return new Response(JSON.stringify(responseData));
} catch (error_message) {
if (error_message instanceof Error) {
console.log(error_message)
error(404, {
message: error_message.message
});
Expand Down

0 comments on commit 6bc7397

Please sign in to comment.