umami/queries/analytics/stats/getRealtimeData.js
Brian Cao 78338205a3
Feat/um 62 prisma property names (#1562)
* checkpoint

* fix pg schema

* fix mysql schema

* change property names
2022-10-10 13:42:18 -07:00

31 lines
811 B
JavaScript

import { getPageviews } from '../pageview/getPageviews';
import { getSessions } from '../session/getSessions';
import { getEvents } from '../event/getEvents';
export async function getRealtimeData(websites, time) {
const [pageviews, sessions, events] = await Promise.all([
getPageviews(websites, time),
getSessions(websites, time),
getEvents(websites, time),
]);
return {
pageviews: pageviews.map(({ pageviewId, ...props }) => ({
__id: `p${pageviewId}`,
pageviewId,
...props,
})),
sessions: sessions.map(({ sessionId, ...props }) => ({
__id: `s${sessionId}`,
sessionId,
...props,
})),
events: events.map(({ eventId, ...props }) => ({
__id: `e${eventId}`,
eventId,
...props,
})),
timestamp: Date.now(),
};
}