mirror of
https://github.com/umami-software/umami.git
synced 2025-12-08 05:12:36 +01:00
Resolve issues in event data
This commit is contained in:
parent
38445fce7a
commit
c3e261fc50
8 changed files with 23 additions and 26 deletions
|
|
@ -5,16 +5,17 @@ import { NextApiResponse } from 'next';
|
|||
import { ok, methodNotAllowed, unauthorized } from 'next-basics';
|
||||
import { getEventDataEvents } from 'queries';
|
||||
|
||||
export interface EventDataFieldsRequestBody {
|
||||
export interface EventDataEventsRequestQuery {
|
||||
websiteId: string;
|
||||
dateRange: {
|
||||
startDate: string;
|
||||
endDate: string;
|
||||
};
|
||||
event?: string;
|
||||
}
|
||||
|
||||
export default async (
|
||||
req: NextApiRequestQueryBody<any, EventDataFieldsRequestBody>,
|
||||
req: NextApiRequestQueryBody<EventDataEventsRequestQuery>,
|
||||
res: NextApiResponse<any>,
|
||||
) => {
|
||||
await useCors(req, res);
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ import { NextApiResponse } from 'next';
|
|||
import { ok, methodNotAllowed, unauthorized } from 'next-basics';
|
||||
import { getEventDataFields } from 'queries';
|
||||
|
||||
export interface EventDataFieldsRequestBody {
|
||||
export interface EventDataFieldsRequestQuery {
|
||||
websiteId: string;
|
||||
dateRange: {
|
||||
startDate: string;
|
||||
|
|
@ -15,7 +15,7 @@ export interface EventDataFieldsRequestBody {
|
|||
}
|
||||
|
||||
export default async (
|
||||
req: NextApiRequestQueryBody<any, EventDataFieldsRequestBody>,
|
||||
req: NextApiRequestQueryBody<EventDataFieldsRequestQuery>,
|
||||
res: NextApiResponse<any>,
|
||||
) => {
|
||||
await useCors(req, res);
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ import { NextApiResponse } from 'next';
|
|||
import { ok, methodNotAllowed, unauthorized } from 'next-basics';
|
||||
import { getEventDataFields } from 'queries';
|
||||
|
||||
export interface EventDataRequestBody {
|
||||
export interface EventDataStatsRequestQuery {
|
||||
websiteId: string;
|
||||
dateRange: {
|
||||
startDate: string;
|
||||
|
|
@ -15,7 +15,7 @@ export interface EventDataRequestBody {
|
|||
}
|
||||
|
||||
export default async (
|
||||
req: NextApiRequestQueryBody<any, EventDataRequestBody>,
|
||||
req: NextApiRequestQueryBody<EventDataStatsRequestQuery>,
|
||||
res: NextApiResponse<any>,
|
||||
) => {
|
||||
await useCors(req, res);
|
||||
|
|
@ -32,18 +32,18 @@ export default async (
|
|||
const endDate = new Date(+endAt);
|
||||
|
||||
const results = await getEventDataFields(websiteId, { startDate, endDate });
|
||||
const events = new Set();
|
||||
const fields = new Set();
|
||||
|
||||
const data = results.reduce(
|
||||
(obj, row) => {
|
||||
events.add(row.fieldName);
|
||||
fields.add(row.fieldName);
|
||||
obj.records += Number(row.total);
|
||||
return obj;
|
||||
},
|
||||
{ fields: results.length, records: 0 },
|
||||
{ events: results.length, records: 0 },
|
||||
);
|
||||
|
||||
return ok(res, { ...data, events: events.size });
|
||||
return ok(res, { ...data, fields: fields.size });
|
||||
}
|
||||
|
||||
return methodNotAllowed(res);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue