mirror of
https://github.com/docmost/docmost.git
synced 2026-08-30 02:25:01 +08:00
support hasPrevPage boolean
This commit is contained in:
@@ -110,7 +110,8 @@ type CursorPaginationResultRow<
|
|||||||
|
|
||||||
type CursorPaginationMeta = {
|
type CursorPaginationMeta = {
|
||||||
limit: number;
|
limit: number;
|
||||||
hasNextPage: boolean;
|
hasNextPage?: boolean;
|
||||||
|
hasPrevPage?: boolean;
|
||||||
nextCursor: string | null;
|
nextCursor: string | null;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -233,15 +234,19 @@ export async function executeWithCursorPagination<
|
|||||||
|
|
||||||
const rows = await qb.limit(opts.perPage + 1).execute();
|
const rows = await qb.limit(opts.perPage + 1).execute();
|
||||||
|
|
||||||
const hasNextPage = rows.length > opts.perPage;
|
const hasNextPage = reversed ? true : rows.length > opts.perPage;
|
||||||
|
const hasPrevPage = !reversed ? undefined : rows.length > opts.perPage;
|
||||||
|
|
||||||
// If we fetched an extra row to determine if we have a next page, that
|
// If we fetched an extra row to determine if we have a next page, that
|
||||||
// shouldn't be in the returned results
|
// shouldn't be in the returned results
|
||||||
if (hasNextPage) rows.pop();
|
if (rows.length > opts.perPage) rows.pop();
|
||||||
|
|
||||||
if (reversed) rows.reverse();
|
if (reversed) rows.reverse();
|
||||||
|
|
||||||
|
//const startRow = rows[0];
|
||||||
const endRow = rows[rows.length - 1];
|
const endRow = rows[rows.length - 1];
|
||||||
|
|
||||||
|
//const startCursor = startRow ? generateCursor(startRow) : null;
|
||||||
const nextCursor = hasNextPage && endRow ? generateCursor(endRow) : null;
|
const nextCursor = hasNextPage && endRow ? generateCursor(endRow) : null;
|
||||||
|
|
||||||
return {
|
return {
|
||||||
@@ -258,6 +263,7 @@ export async function executeWithCursorPagination<
|
|||||||
meta: {
|
meta: {
|
||||||
limit: opts.perPage,
|
limit: opts.perPage,
|
||||||
hasNextPage,
|
hasNextPage,
|
||||||
|
hasPrevPage: hasPrevPage ?? !!opts.after,
|
||||||
nextCursor,
|
nextCursor,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user