mirror of
https://github.com/umami-software/umami.git
synced 2026-02-06 13:47:15 +01:00
Merge remote-tracking branch 'origin/dev' into dev
# Conflicts: # src/lib/constants.ts
This commit is contained in:
commit
19d5ac0a4c
23 changed files with 500 additions and 10 deletions
|
|
@ -27,7 +27,7 @@ const schema: YupRequest = {
|
|||
websiteId: yup.string().uuid().required(),
|
||||
type: yup
|
||||
.string()
|
||||
.matches(/funnel|insights|retention|utm|goals|journey/i)
|
||||
.matches(/funnel|insights|retention|utm|goals|journey|revenue/i)
|
||||
.required(),
|
||||
name: yup.string().max(200).required(),
|
||||
description: yup.string().max(500),
|
||||
|
|
|
|||
|
|
@ -27,7 +27,7 @@ const schema = {
|
|||
name: yup.string().max(200).required(),
|
||||
type: yup
|
||||
.string()
|
||||
.matches(/funnel|insights|retention|utm|goals|journey/i)
|
||||
.matches(/funnel|insights|retention|utm|goals|journey|revenue/i)
|
||||
.required(),
|
||||
description: yup.string().max(500),
|
||||
parameters: yup
|
||||
|
|
|
|||
71
src/pages/api/reports/revenue.ts
Normal file
71
src/pages/api/reports/revenue.ts
Normal file
|
|
@ -0,0 +1,71 @@
|
|||
import { canViewWebsite } from 'lib/auth';
|
||||
import { useAuth, useCors, useValidate } from 'lib/middleware';
|
||||
import { NextApiRequestQueryBody } from 'lib/types';
|
||||
import { TimezoneTest, UnitTypeTest } from 'lib/yup';
|
||||
import { NextApiResponse } from 'next';
|
||||
import { methodNotAllowed, ok, unauthorized } from 'next-basics';
|
||||
import { getRevenue } from 'queries/analytics/reports/getRevenue';
|
||||
import * as yup from 'yup';
|
||||
|
||||
export interface RetentionRequestBody {
|
||||
websiteId: string;
|
||||
dateRange: { startDate: string; endDate: string; unit?: string; timezone?: string };
|
||||
eventName: string;
|
||||
revenueProperty: string;
|
||||
userProperty: string;
|
||||
}
|
||||
|
||||
const schema = {
|
||||
POST: yup.object().shape({
|
||||
websiteId: yup.string().uuid().required(),
|
||||
dateRange: yup
|
||||
.object()
|
||||
.shape({
|
||||
startDate: yup.date().required(),
|
||||
endDate: yup.date().required(),
|
||||
unit: UnitTypeTest,
|
||||
timezone: TimezoneTest,
|
||||
})
|
||||
.required(),
|
||||
eventName: yup.string().required(),
|
||||
revenueProperty: yup.string().required(),
|
||||
userProperty: yup.string(),
|
||||
}),
|
||||
};
|
||||
|
||||
export default async (
|
||||
req: NextApiRequestQueryBody<any, RetentionRequestBody>,
|
||||
res: NextApiResponse,
|
||||
) => {
|
||||
await useCors(req, res);
|
||||
await useAuth(req, res);
|
||||
await useValidate(schema, req, res);
|
||||
|
||||
if (req.method === 'POST') {
|
||||
const {
|
||||
websiteId,
|
||||
dateRange: { startDate, endDate, unit, timezone },
|
||||
eventName,
|
||||
revenueProperty,
|
||||
userProperty,
|
||||
} = req.body;
|
||||
|
||||
if (!(await canViewWebsite(req.auth, websiteId))) {
|
||||
return unauthorized(res);
|
||||
}
|
||||
|
||||
const data = await getRevenue(websiteId, {
|
||||
startDate: new Date(startDate),
|
||||
endDate: new Date(endDate),
|
||||
unit,
|
||||
timezone,
|
||||
eventName,
|
||||
revenueProperty,
|
||||
userProperty,
|
||||
});
|
||||
|
||||
return ok(res, data);
|
||||
}
|
||||
|
||||
return methodNotAllowed(res);
|
||||
};
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
import { canViewWebsite } from 'lib/auth';
|
||||
import { useAuth, useCors, useValidate } from 'lib/middleware';
|
||||
import { getRequestFilters, getRequestDateRange } from 'lib/request';
|
||||
import { getRequestDateRange, getRequestFilters } from 'lib/request';
|
||||
import { NextApiRequestQueryBody, WebsiteMetric } from 'lib/types';
|
||||
import { TimezoneTest, UnitTypeTest } from 'lib/yup';
|
||||
import { NextApiResponse } from 'next';
|
||||
|
|
@ -17,6 +17,7 @@ export interface WebsiteEventsRequestQuery {
|
|||
url: string;
|
||||
referrer?: string;
|
||||
title?: string;
|
||||
host?: string;
|
||||
os?: string;
|
||||
browser?: string;
|
||||
device?: string;
|
||||
|
|
@ -35,6 +36,7 @@ const schema = {
|
|||
url: yup.string(),
|
||||
referrer: yup.string(),
|
||||
title: yup.string(),
|
||||
host: yup.string(),
|
||||
os: yup.string(),
|
||||
browser: yup.string(),
|
||||
device: yup.string(),
|
||||
|
|
|
|||
|
|
@ -17,6 +17,7 @@ export interface WebsiteMetricsRequestQuery {
|
|||
referrer?: string;
|
||||
title?: string;
|
||||
query?: string;
|
||||
host?: string;
|
||||
os?: string;
|
||||
browser?: string;
|
||||
device?: string;
|
||||
|
|
@ -40,6 +41,7 @@ const schema = {
|
|||
referrer: yup.string(),
|
||||
title: yup.string(),
|
||||
query: yup.string(),
|
||||
host: yup.string(),
|
||||
os: yup.string(),
|
||||
browser: yup.string(),
|
||||
device: yup.string(),
|
||||
|
|
|
|||
|
|
@ -17,8 +17,8 @@ export interface WebsitePageviewRequestQuery {
|
|||
timezone?: string;
|
||||
url?: string;
|
||||
referrer?: string;
|
||||
host?: string;
|
||||
title?: string;
|
||||
host?: string;
|
||||
os?: string;
|
||||
browser?: string;
|
||||
device?: string;
|
||||
|
|
@ -37,8 +37,8 @@ const schema = {
|
|||
timezone: TimezoneTest,
|
||||
url: yup.string(),
|
||||
referrer: yup.string(),
|
||||
host: yup.string(),
|
||||
title: yup.string(),
|
||||
host: yup.string(),
|
||||
os: yup.string(),
|
||||
browser: yup.string(),
|
||||
device: yup.string(),
|
||||
|
|
|
|||
|
|
@ -14,10 +14,10 @@ export interface WebsiteStatsRequestQuery {
|
|||
endAt: number;
|
||||
url?: string;
|
||||
referrer?: string;
|
||||
host?: string;
|
||||
title?: string;
|
||||
query?: string;
|
||||
event?: string;
|
||||
host?: string;
|
||||
os?: string;
|
||||
browser?: string;
|
||||
device?: string;
|
||||
|
|
@ -34,10 +34,10 @@ const schema = {
|
|||
endAt: yup.number().required(),
|
||||
url: yup.string(),
|
||||
referrer: yup.string(),
|
||||
host: yup.string(),
|
||||
title: yup.string(),
|
||||
query: yup.string(),
|
||||
event: yup.string(),
|
||||
host: yup.string(),
|
||||
os: yup.string(),
|
||||
browser: yup.string(),
|
||||
device: yup.string(),
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue