19 lines
604 B
TypeScript
19 lines
604 B
TypeScript
![]() |
import type { ObjectWithRequiredFields } from "@/types/object-with-required-fields";
|
||
|
import type { PaginationParams } from "./types";
|
||
|
|
||
|
const DEFAULT_PAGE = 1;
|
||
|
const DEFAULT_LIMIT = 100;
|
||
|
|
||
|
export const determinePaginationParameters = ({
|
||
|
page: optionalPage,
|
||
|
limit: optionalLimit,
|
||
|
}: PaginationParams): ObjectWithRequiredFields<PaginationParams> => {
|
||
|
const page = !optionalPage || optionalPage < 1 ? DEFAULT_PAGE : optionalPage;
|
||
|
const limit = !optionalLimit || optionalLimit < 1 ? DEFAULT_LIMIT : optionalLimit;
|
||
|
|
||
|
return {
|
||
|
page,
|
||
|
limit: limit > DEFAULT_LIMIT ? DEFAULT_LIMIT : limit,
|
||
|
};
|
||
|
};
|