feat: added cursor-based pagination to checklistitems
This commit is contained in:
@@ -0,0 +1,25 @@
|
||||
import { CursorPaginatedResult } from "../interfaces/cursor-paginated-result.interface";
|
||||
|
||||
export function buildCursorPageFormat<T extends { createdAt: Date }>(
|
||||
data: T[],
|
||||
limit: number,
|
||||
previousCursor?: Date,
|
||||
): CursorPaginatedResult<T> {
|
||||
const hasMore = data.length > limit;
|
||||
|
||||
if (hasMore) data.pop();
|
||||
|
||||
const nextCursor = hasMore ? data[data.length - 1].createdAt.toISOString() : null;
|
||||
|
||||
const prevCursor = previousCursor ? previousCursor.toISOString() : null;
|
||||
|
||||
return {
|
||||
data,
|
||||
meta: {
|
||||
nextCursor,
|
||||
prevCursor,
|
||||
hasMore,
|
||||
limit,
|
||||
},
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user