All files / munch-ease-frontend/src/domain pagination.ts

100% Statements 13/13
50% Branches 2/4
100% Functions 1/1
100% Lines 13/13

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 141x 1x 1x 1x 1x 2x 2x 2x 2x 2x 2x 2x 2x  
export type Page<T> = { items: T[]; next?: string | null; prev?: string | null; total?: number | null }
 
type PageLike<T> = { items?: T[]; nextCursor?: string | null; prevCursor?: string | null; total?: number | null }
 
export function fromOpenApiPage<TIn, TOut>(page: PageLike<TIn> | null | undefined, mapItem: (i: TIn) => TOut): Page<TOut> {
  if (!page) return { items: [] }
  return {
    items: (page.items ?? []).map((i) => mapItem(i)),
    next: page.nextCursor ?? null,
    prev: page.prevCursor ?? null,
    total: page.total ?? null,
  }
}