1
0
Fork 0
mirror of synced 2024-08-05 13:21:26 +12:00

Fixing some issues with using offsets.

This commit is contained in:
mike12345567 2024-06-14 18:27:23 +01:00
parent e402f9c571
commit 908b77fd9b

View file

@ -33,9 +33,9 @@ export async function search(
let bookmark =
(params.bookmark && parseInt(params.bookmark as string)) || undefined
if (paginate && !bookmark) {
bookmark = 1
bookmark = 0
}
let paginateObj = {}
let paginateObj: PaginationJson | undefined
if (paginate && !limit) {
throw new Error("Cannot paginate query without a limit")
@ -45,7 +45,9 @@ export async function search(
paginateObj = {
// add one so we can track if there is another page
limit: limit + 1,
page: bookmark,
}
if (bookmark) {
paginateObj.offset = limit * bookmark
}
} else if (params && limit) {
paginateObj = {
@ -97,7 +99,11 @@ export async function search(
})
// need wrapper object for bookmarks etc when paginating
return { rows, hasNextPage, bookmark: bookmark && bookmark + 1 }
const response: SearchResponse<Row> = { rows, hasNextPage }
if (hasNextPage && bookmark != null) {
response.bookmark = bookmark + 1
}
return response
} catch (err: any) {
if (err.message && err.message.includes("does not exist")) {
throw new Error(