initial commit

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
BOHA
2026-03-23 08:46:51 +01:00
commit 4608494a3f
130 changed files with 40361 additions and 0 deletions

28
src/utils/pagination.ts Normal file
View File

@@ -0,0 +1,28 @@
import { PaginationQuery, PaginationMeta } from '../types';
export function parsePagination(query: Record<string, unknown>): {
page: number;
limit: number;
skip: number;
sort: string;
order: 'asc' | 'desc';
search: string;
} {
const page = Math.max(1, parseInt(String(query.page || '1'), 10) || 1);
const limit = Math.min(100, Math.max(1, parseInt(String(query.limit || query.per_page || '25'), 10) || 25));
const sort = String(query.sort || 'id');
const order = String(query.order || '').toLowerCase() === 'asc' ? 'asc' : 'desc';
const search = String(query.search || '');
return { page, limit, skip: (page - 1) * limit, sort, order, search };
}
export function buildPaginationMeta(total: number, page: number, limit: number): PaginationMeta {
return {
page,
limit,
per_page: limit,
total,
total_pages: Math.ceil(total / limit),
};
}