switch to monorepo structure
This commit is contained in:
32
packages/server/src/bookmark/handlers.ts
Normal file
32
packages/server/src/bookmark/handlers.ts
Normal file
@@ -0,0 +1,32 @@
|
||||
import { type } from "arktype"
|
||||
import { db } from "~/database.ts"
|
||||
import { HttpError } from "~/error.ts"
|
||||
import type { User } from "~/user/user.ts"
|
||||
|
||||
const BOOKMARK_PAGINATION_LIMIT = 100
|
||||
|
||||
const ListUserBookmarksParams = type({
|
||||
limit: ["number", "=", BOOKMARK_PAGINATION_LIMIT],
|
||||
skip: ["number", "=", 5],
|
||||
})
|
||||
|
||||
const listBookmarksQuery = db.query(
|
||||
"SELECT id, kind, title, url FROM bookmarks WHERE user_id = $userId LIMIT $limit OFFSET $skip",
|
||||
)
|
||||
|
||||
async function listUserBookmarks(request: Bun.BunRequest<"/api/bookmarks">, user: User) {
|
||||
const queryParams = ListUserBookmarksParams(request.params)
|
||||
if (queryParams instanceof type.errors) {
|
||||
throw new HttpError(400, queryParams.summary)
|
||||
}
|
||||
|
||||
const results = listBookmarksQuery.all({
|
||||
userId: user.id,
|
||||
limit: queryParams.limit,
|
||||
skip: queryParams.skip,
|
||||
})
|
||||
|
||||
return Response.json(results, { status: 200 })
|
||||
}
|
||||
|
||||
export { listUserBookmarks }
|
Reference in New Issue
Block a user