- Initial setup and all features from develop branch - Includes: auth, deploy, docker, style fixes - K3S deployment configuration
43 lines
879 B
TypeScript
43 lines
879 B
TypeScript
export interface PaginationParams {
|
|
page?: number;
|
|
limit?: number;
|
|
}
|
|
|
|
export interface PaginatedResponse<T> {
|
|
data: T[];
|
|
pagination: {
|
|
page: number;
|
|
limit: number;
|
|
total: number;
|
|
totalPages: number;
|
|
};
|
|
}
|
|
|
|
export function getPaginationParams(
|
|
searchParams: URLSearchParams,
|
|
defaultLimit = 12
|
|
): { page: number; limit: number; skip: number } {
|
|
const page = Math.max(1, parseInt(searchParams.get('page') || '1', 10));
|
|
const limit = Math.max(1, parseInt(searchParams.get('limit') || String(defaultLimit), 10));
|
|
const skip = (page - 1) * limit;
|
|
|
|
return { page, limit, skip };
|
|
}
|
|
|
|
export function createPaginatedResponse<T>(
|
|
data: T[],
|
|
total: number,
|
|
page: number,
|
|
limit: number
|
|
): PaginatedResponse<T> {
|
|
return {
|
|
data,
|
|
pagination: {
|
|
page,
|
|
limit,
|
|
total,
|
|
totalPages: Math.ceil(total / limit),
|
|
},
|
|
};
|
|
}
|