21 lines
805 B
TypeScript
21 lines
805 B
TypeScript
import { NextRequest } from 'next/server';
|
|
import { parseDateRange } from '@/lib/analytics/shared';
|
|
import type { AnalyticsFilters } from '@/lib/analytics/shared';
|
|
|
|
export function parseAnalyticsParams(request: NextRequest): AnalyticsFilters {
|
|
const { searchParams } = new URL(request.url);
|
|
const from = searchParams.get('from');
|
|
const to = searchParams.get('to');
|
|
const preset = searchParams.get('preset');
|
|
const categoryId = searchParams.get('categoryId');
|
|
const productId = searchParams.get('productId');
|
|
const comparisonEnabled = searchParams.get('comparison') === 'true';
|
|
|
|
return {
|
|
dateRange: parseDateRange(from, to, preset),
|
|
categoryId: categoryId ? parseInt(categoryId) : undefined,
|
|
productId: productId ? parseInt(productId) : undefined,
|
|
comparisonEnabled,
|
|
};
|
|
}
|