Files
n8n-enterprise-unlocked/packages/cli/src/middlewares/list-query/dtos/pagination.dto.ts
2025-02-27 09:30:55 +02:00

25 lines
581 B
TypeScript

import { UnexpectedError } from 'n8n-workflow';
import { isIntegerString } from '@/utils';
export class Pagination {
static fromString(rawTake: string, rawSkip: string) {
if (!isIntegerString(rawTake)) {
throw new UnexpectedError('Parameter take is not an integer string');
}
if (!isIntegerString(rawSkip)) {
throw new UnexpectedError('Parameter skip is not an integer string');
}
const [take, skip] = [rawTake, rawSkip].map((o) => parseInt(o, 10));
const MAX_ITEMS_PER_PAGE = 50;
return {
take: Math.min(take, MAX_ITEMS_PER_PAGE),
skip,
};
}
}