-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
53d1743
commit 8c98a8a
Showing
1 changed file
with
38 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import { error } from "@sveltejs/kit"; | ||
import type { RequestHandler } from "./$types"; | ||
|
||
export const GET: RequestHandler = async ({ url, locals: { supabase } }) => { | ||
const username = String(url.searchParams.get("username")); | ||
const status = String(url.searchParams.get("status")); | ||
const limit = Number(url.searchParams.get("limit") || 10); | ||
|
||
if (!username) { | ||
throw error(400, "username is required"); | ||
} | ||
|
||
if (!status) { | ||
throw error(400, "status is required"); | ||
} | ||
|
||
const { data: user, error: user_error } = await supabase | ||
.from("users") | ||
.select() | ||
.eq("username", username) | ||
.single(); | ||
|
||
if (user_error) { | ||
throw error(404, "User not found"); | ||
} | ||
|
||
const { data: books, error: books_error } = await supabase | ||
.from("books") | ||
.select() | ||
.eq("owner", user.id) | ||
.eq("status", status) | ||
.order("finished", { ascending: false }) | ||
.limit(limit); | ||
|
||
if (books_error) throw error; | ||
|
||
return new Response(JSON.stringify(books)); | ||
}; |
8c98a8a
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
bklst – ./
bklst-matteotagliatti.vercel.app
bklst.matteotagliatti.it
bklst-git-master-matteotagliatti.vercel.app
bklst-nextpages.vercel.app