2023-07-04 08:24:34 +03:00
|
|
|
import { DEFAULT_PER_PAGE_OPTIONS } from './config';
|
2023-06-23 21:39:59 +03:00
|
|
|
import { Pagination } from './types';
|
|
|
|
|
|
2023-07-04 08:24:34 +03:00
|
|
|
export const checkIsValidPaginationData = (
|
|
|
|
|
{ limit, offset }: Pagination,
|
|
|
|
|
perPageOptions: number[],
|
|
|
|
|
): boolean =>
|
2023-06-23 21:39:59 +03:00
|
|
|
Boolean(
|
2023-07-04 08:24:34 +03:00
|
|
|
Number.isInteger(limit) &&
|
|
|
|
|
limit > 0 &&
|
|
|
|
|
offset >= 0 &&
|
|
|
|
|
perPageOptions.find((option) => option === limit),
|
2023-06-23 21:39:59 +03:00
|
|
|
);
|
2023-07-04 08:24:34 +03:00
|
|
|
|
|
|
|
|
export const getDefaultPaginationConfig = (
|
|
|
|
|
perPageOptions = DEFAULT_PER_PAGE_OPTIONS,
|
|
|
|
|
): Pagination => ({
|
|
|
|
|
offset: 0,
|
|
|
|
|
limit: perPageOptions[0],
|
|
|
|
|
});
|