mirror of
https://github.com/umami-software/umami.git
synced 2026-02-12 00:27:11 +01:00
Initial Typescript models.
This commit is contained in:
parent
04e9f06e93
commit
0aaba8cbd1
74 changed files with 1144 additions and 768 deletions
|
|
@ -3,8 +3,18 @@ import { allowQuery } from 'lib/auth';
|
|||
import { useAuth, useCors } from 'lib/middleware';
|
||||
import { getActiveVisitors } from 'queries';
|
||||
import { TYPE_WEBSITE } from 'lib/constants';
|
||||
import { WebsiteActive } from 'interface/api/models';
|
||||
import { NextApiRequestQueryBody } from 'interface/api/nextApi';
|
||||
import { NextApiResponse } from 'next';
|
||||
|
||||
export default async (req, res) => {
|
||||
export interface WebsiteActiveRequestQuery {
|
||||
id: string;
|
||||
}
|
||||
|
||||
export default async (
|
||||
req: NextApiRequestQueryBody<WebsiteActiveRequestQuery>,
|
||||
res: NextApiResponse<WebsiteActive>,
|
||||
) => {
|
||||
await useCors(req, res);
|
||||
await useAuth(req, res);
|
||||
|
||||
|
|
@ -4,8 +4,27 @@ import { ok, badRequest, methodNotAllowed, unauthorized } from 'next-basics';
|
|||
import { allowQuery } from 'lib/auth';
|
||||
import { useAuth, useCors } from 'lib/middleware';
|
||||
import { TYPE_WEBSITE } from 'lib/constants';
|
||||
import { NextApiRequestQueryBody } from 'interface/api/nextApi';
|
||||
import { NextApiResponse } from 'next';
|
||||
import { WebsiteMetric } from 'interface/api/models';
|
||||
|
||||
export default async (req, res) => {
|
||||
export interface WebsiteEventDataRequestQuery {
|
||||
id: string;
|
||||
}
|
||||
|
||||
export interface WebsiteEventDataRequestBody {
|
||||
start_at: string;
|
||||
end_at: string;
|
||||
timezone: string;
|
||||
event_name: string;
|
||||
columns: { [key: string]: 'count' | 'max' | 'min' | 'avg' | 'sum' };
|
||||
filters?: { [key: string]: any };
|
||||
}
|
||||
|
||||
export default async (
|
||||
req: NextApiRequestQueryBody<WebsiteEventDataRequestQuery, WebsiteEventDataRequestBody>,
|
||||
res: NextApiResponse<WebsiteMetric>,
|
||||
) => {
|
||||
await useCors(req, res);
|
||||
await useAuth(req, res);
|
||||
|
||||
|
|
@ -1,13 +1,29 @@
|
|||
import moment from 'moment-timezone';
|
||||
import { getEventMetrics } from 'queries';
|
||||
import { ok, badRequest, methodNotAllowed, unauthorized } from 'next-basics';
|
||||
import { WebsiteMetric } from 'interface/api/models';
|
||||
import { NextApiRequestQueryBody } from 'interface/api/nextApi';
|
||||
import { allowQuery } from 'lib/auth';
|
||||
import { useAuth, useCors } from 'lib/middleware';
|
||||
import { TYPE_WEBSITE } from 'lib/constants';
|
||||
import { useAuth, useCors } from 'lib/middleware';
|
||||
import moment from 'moment-timezone';
|
||||
import { NextApiResponse } from 'next';
|
||||
import { badRequest, methodNotAllowed, ok, unauthorized } from 'next-basics';
|
||||
import { getEventMetrics } from 'queries';
|
||||
|
||||
const unitTypes = ['year', 'month', 'hour', 'day'];
|
||||
|
||||
export default async (req, res) => {
|
||||
export interface WebsiteEventsRequestQuery {
|
||||
id: string;
|
||||
start_at: string;
|
||||
end_at: string;
|
||||
unit: string;
|
||||
tz: string;
|
||||
url: string;
|
||||
event_name: string;
|
||||
}
|
||||
|
||||
export default async (
|
||||
req: NextApiRequestQueryBody<WebsiteEventsRequestQuery>,
|
||||
res: NextApiResponse<WebsiteMetric>,
|
||||
) => {
|
||||
await useCors(req, res);
|
||||
await useAuth(req, res);
|
||||
|
||||
|
|
@ -24,9 +40,15 @@ export default async (req, res) => {
|
|||
const startDate = new Date(+start_at);
|
||||
const endDate = new Date(+end_at);
|
||||
|
||||
const events = await getEventMetrics(websiteId, startDate, endDate, tz, unit, {
|
||||
url,
|
||||
eventName: event_name,
|
||||
const events = await getEventMetrics(websiteId, {
|
||||
startDate,
|
||||
endDate,
|
||||
timezone: tz,
|
||||
unit,
|
||||
filters: {
|
||||
url,
|
||||
eventName: event_name,
|
||||
},
|
||||
});
|
||||
|
||||
return ok(res, events);
|
||||
|
|
@ -3,8 +3,24 @@ import { useAuth, useCors } from 'lib/middleware';
|
|||
import { methodNotAllowed, ok, serverError, unauthorized } from 'next-basics';
|
||||
import { deleteWebsite, getWebsite, updateWebsite } from 'queries';
|
||||
import { TYPE_WEBSITE } from 'lib/constants';
|
||||
import { NextApiRequestQueryBody } from 'interface/api/nextApi';
|
||||
import { NextApiResponse } from 'next';
|
||||
import { Website } from 'interface/api/models';
|
||||
|
||||
export default async (req, res) => {
|
||||
export interface WebsiteReqeustQuery {
|
||||
id: string;
|
||||
}
|
||||
|
||||
export interface WebsiteReqeustBody {
|
||||
name: string;
|
||||
domain: string;
|
||||
shareId: string;
|
||||
}
|
||||
|
||||
export default async (
|
||||
req: NextApiRequestQueryBody<WebsiteReqeustQuery, WebsiteReqeustBody>,
|
||||
res: NextApiResponse<Website | any>,
|
||||
) => {
|
||||
await useCors(req, res);
|
||||
await useAuth(req, res);
|
||||
|
||||
|
|
@ -1,6 +1,9 @@
|
|||
import { WebsiteMetric } from 'interface/api/models';
|
||||
import { NextApiRequestQueryBody } from 'interface/api/nextApi';
|
||||
import { allowQuery } from 'lib/auth';
|
||||
import { FILTER_IGNORED, TYPE_WEBSITE } from 'lib/constants';
|
||||
import { useAuth, useCors } from 'lib/middleware';
|
||||
import { NextApiResponse } from 'next';
|
||||
import { badRequest, methodNotAllowed, ok, unauthorized } from 'next-basics';
|
||||
import { getPageviewMetrics, getSessionMetrics, getWebsite } from 'queries';
|
||||
|
||||
|
|
@ -33,7 +36,23 @@ function getColumn(type) {
|
|||
return type;
|
||||
}
|
||||
|
||||
export default async (req, res) => {
|
||||
export interface WebsiteMetricsReqeustQuery {
|
||||
id: string;
|
||||
type: string;
|
||||
start_at: number;
|
||||
end_at: number;
|
||||
url: string;
|
||||
referrer: string;
|
||||
os: string;
|
||||
browser: string;
|
||||
device: string;
|
||||
country: string;
|
||||
}
|
||||
|
||||
export default async (
|
||||
req: NextApiRequestQueryBody<WebsiteMetricsReqeustQuery>,
|
||||
res: NextApiResponse<WebsiteMetric[]>,
|
||||
) => {
|
||||
await useCors(req, res);
|
||||
await useAuth(req, res);
|
||||
|
||||
|
|
@ -1,13 +1,34 @@
|
|||
import moment from 'moment-timezone';
|
||||
import { getPageviewStats } from 'queries';
|
||||
import { ok, badRequest, methodNotAllowed, unauthorized } from 'next-basics';
|
||||
import { WebsitePageviews } from 'interface/api/models';
|
||||
import { NextApiRequestQueryBody } from 'interface/api/nextApi';
|
||||
import { allowQuery } from 'lib/auth';
|
||||
import { useAuth, useCors } from 'lib/middleware';
|
||||
import { TYPE_WEBSITE } from 'lib/constants';
|
||||
import { useAuth, useCors } from 'lib/middleware';
|
||||
import moment from 'moment-timezone';
|
||||
import { NextApiResponse } from 'next';
|
||||
import { badRequest, methodNotAllowed, ok, unauthorized } from 'next-basics';
|
||||
import { getPageviewStats } from 'queries';
|
||||
|
||||
const unitTypes = ['year', 'month', 'hour', 'day'];
|
||||
|
||||
export default async (req, res) => {
|
||||
export interface WebsitePageviewReqeustQuery {
|
||||
id: string;
|
||||
websiteId: string;
|
||||
start_at: number;
|
||||
end_at: number;
|
||||
unit: string;
|
||||
tz: string;
|
||||
url?: string;
|
||||
referrer?: string;
|
||||
os?: string;
|
||||
browser?: string;
|
||||
device?: string;
|
||||
country?: string;
|
||||
}
|
||||
|
||||
export default async (
|
||||
req: NextApiRequestQueryBody<WebsitePageviewReqeustQuery>,
|
||||
res: NextApiResponse<WebsitePageviews>,
|
||||
) => {
|
||||
await useCors(req, res);
|
||||
await useAuth(req, res);
|
||||
|
||||
|
|
@ -39,8 +60,8 @@ export default async (req, res) => {
|
|||
|
||||
const [pageviews, sessions] = await Promise.all([
|
||||
getPageviewStats(websiteId, {
|
||||
start_at: startDate,
|
||||
end_at: endDate,
|
||||
startDate,
|
||||
endDate,
|
||||
timezone: tz,
|
||||
unit,
|
||||
count: '*',
|
||||
|
|
@ -54,8 +75,8 @@ export default async (req, res) => {
|
|||
},
|
||||
}),
|
||||
getPageviewStats(websiteId, {
|
||||
start_at: startDate,
|
||||
end_at: endDate,
|
||||
startDate,
|
||||
endDate,
|
||||
timezone: tz,
|
||||
unit,
|
||||
count: 'distinct pageview.',
|
||||
|
|
@ -3,8 +3,17 @@ import { methodNotAllowed, ok, unauthorized } from 'next-basics';
|
|||
import { allowQuery } from 'lib/auth';
|
||||
import { useAuth, useCors } from 'lib/middleware';
|
||||
import { TYPE_WEBSITE } from 'lib/constants';
|
||||
import { NextApiRequestQueryBody } from 'interface/api/nextApi';
|
||||
import { NextApiResponse } from 'next';
|
||||
|
||||
export default async (req, res) => {
|
||||
export interface WebsiteResetReqeustQuery {
|
||||
id: string;
|
||||
}
|
||||
|
||||
export default async (
|
||||
req: NextApiRequestQueryBody<WebsiteResetReqeustQuery>,
|
||||
res: NextApiResponse,
|
||||
) => {
|
||||
await useCors(req, res);
|
||||
await useAuth(req, res);
|
||||
|
||||
|
|
@ -3,8 +3,27 @@ import { methodNotAllowed, ok, unauthorized } from 'next-basics';
|
|||
import { allowQuery } from 'lib/auth';
|
||||
import { useAuth, useCors } from 'lib/middleware';
|
||||
import { TYPE_WEBSITE } from 'lib/constants';
|
||||
import { WebsiteStats } from 'interface/api/models';
|
||||
import { NextApiRequestQueryBody } from 'interface/api/nextApi';
|
||||
import { NextApiResponse } from 'next';
|
||||
|
||||
export default async (req, res) => {
|
||||
export interface WebsiteStatsReqeustQuery {
|
||||
id: string;
|
||||
type: string;
|
||||
start_at: number;
|
||||
end_at: number;
|
||||
url: string;
|
||||
referrer: string;
|
||||
os: string;
|
||||
browser: string;
|
||||
device: string;
|
||||
country: string;
|
||||
}
|
||||
|
||||
export default async (
|
||||
req: NextApiRequestQueryBody<WebsiteStatsReqeustQuery>,
|
||||
res: NextApiResponse<WebsiteStats>,
|
||||
) => {
|
||||
await useCors(req, res);
|
||||
await useAuth(req, res);
|
||||
|
||||
|
|
@ -2,8 +2,23 @@ import { createWebsite, getAllWebsites, getUserWebsites } from 'queries';
|
|||
import { ok, methodNotAllowed, getRandomChars } from 'next-basics';
|
||||
import { useAuth, useCors } from 'lib/middleware';
|
||||
import { uuid } from 'lib/crypto';
|
||||
import { NextApiRequestQueryBody } from 'interface/api/nextApi';
|
||||
import { NextApiResponse } from 'next';
|
||||
|
||||
export default async (req, res) => {
|
||||
export interface WebsitesReqeustQuery {
|
||||
include_all?: boolean;
|
||||
}
|
||||
|
||||
export interface WebsitesReqeustBody {
|
||||
name: string;
|
||||
domain: string;
|
||||
enableShareUrl: boolean;
|
||||
}
|
||||
|
||||
export default async (
|
||||
req: NextApiRequestQueryBody<WebsitesReqeustQuery, WebsitesReqeustBody>,
|
||||
res: NextApiResponse,
|
||||
) => {
|
||||
await useCors(req, res);
|
||||
await useAuth(req, res);
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue