//#region src/utils/filtersAndPagination/getFiltersAndPaginationFromBody.ts
const DEFAULT_PAGE_SIZE = 1e3;
const DEFAULT_PAGE = 1;
/**
* Extracts filters and pagination information from the request body.
* @param req - Express request object.
* @returns Object containing filters, page, pageSize, and getNumberOfPages functions.
*/
const getFiltersAndPaginationFromBody = (req) => {
	let filters = {};
	let pageSize = DEFAULT_PAGE_SIZE;
	let page = DEFAULT_PAGE;
	const query = req.query;
	if (typeof query === "object") {
		const { pageSize: pageSizeRequest, page: pageRequest, ...filtersRequest } = query;
		if (typeof pageSizeRequest === "string") pageSize = parseInt(pageSizeRequest, 10);
		else if (typeof pageSizeRequest === "number") pageSize = pageSizeRequest;
		if (typeof pageRequest === "string") page = parseInt(pageRequest, 10);
		else if (typeof pageRequest === "number") page = pageRequest;
		if (filtersRequest && Object.keys(filtersRequest).length > 0) filters = filtersRequest;
	}
	const skip = (page - 1) * pageSize;
	const getNumberOfPages = (totalItems) => Math.ceil(totalItems / pageSize);
	return {
		filters,
		skip,
		page,
		pageSize,
		getNumberOfPages
	};
};

//#endregion
export { getFiltersAndPaginationFromBody };
//# sourceMappingURL=getFiltersAndPaginationFromBody.mjs.map