mirror of
https://github.com/umami-software/umami.git
synced 2026-02-14 17:45:38 +01:00
Added parseDateRangeQuery function.
This commit is contained in:
parent
09af33c77e
commit
1648707fc7
9 changed files with 48 additions and 80 deletions
|
|
@ -1,8 +1,10 @@
|
|||
import { addMinutes, differenceInMinutes } from 'date-fns';
|
||||
import { NextApiResponse } from 'next';
|
||||
import { methodNotAllowed, ok, unauthorized } from 'next-basics';
|
||||
import { canViewWebsite } from 'lib/auth';
|
||||
import { useAuth, useCors } from 'lib/middleware';
|
||||
import { NextApiRequestQueryBody, WebsiteStats } from 'lib/types';
|
||||
import { NextApiResponse } from 'next';
|
||||
import { methodNotAllowed, ok, unauthorized } from 'next-basics';
|
||||
import { parseDateRangeQuery } from 'lib/query';
|
||||
import { getWebsiteStats } from 'queries';
|
||||
|
||||
export interface WebsiteStatsRequestQuery {
|
||||
|
|
@ -31,8 +33,6 @@ export default async (
|
|||
|
||||
const {
|
||||
id: websiteId,
|
||||
startAt,
|
||||
endAt,
|
||||
url,
|
||||
referrer,
|
||||
title,
|
||||
|
|
@ -51,12 +51,10 @@ export default async (
|
|||
return unauthorized(res);
|
||||
}
|
||||
|
||||
const startDate = new Date(+startAt);
|
||||
const endDate = new Date(+endAt);
|
||||
|
||||
const distance = endAt - startAt;
|
||||
const prevStartDate = new Date(+startAt - distance);
|
||||
const prevEndDate = new Date(+endAt - distance);
|
||||
const { startDate, endDate } = await parseDateRangeQuery(req);
|
||||
const diff = differenceInMinutes(endDate, startDate);
|
||||
const prevStartDate = addMinutes(startDate, -diff);
|
||||
const prevEndDate = addMinutes(endDate, -diff);
|
||||
|
||||
const metrics = await getWebsiteStats(websiteId, {
|
||||
startDate,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue