Updated reports.
This commit is contained in:
@@ -1,41 +1,11 @@
|
||||
import { z } from 'zod';
|
||||
import { canViewWebsite } from '@/lib/auth';
|
||||
import { unauthorized, json } from '@/lib/response';
|
||||
import { parseRequest } from '@/lib/request';
|
||||
import { getInsights } from '@/queries';
|
||||
import { reportParms } from '@/lib/schema';
|
||||
|
||||
function convertFilters(filters: any[]) {
|
||||
return filters.reduce((obj, filter) => {
|
||||
obj[filter.name] = filter;
|
||||
|
||||
return obj;
|
||||
}, {});
|
||||
}
|
||||
import { reportResultSchema } from '@/lib/schema';
|
||||
|
||||
export async function POST(request: Request) {
|
||||
const schema = z.object({
|
||||
...reportParms,
|
||||
fields: z
|
||||
.array(
|
||||
z.object({
|
||||
name: z.string(),
|
||||
type: z.string(),
|
||||
label: z.string(),
|
||||
}),
|
||||
)
|
||||
.min(1),
|
||||
filters: z.array(
|
||||
z.object({
|
||||
name: z.string(),
|
||||
type: z.string(),
|
||||
operator: z.string(),
|
||||
value: z.string(),
|
||||
}),
|
||||
),
|
||||
});
|
||||
|
||||
const { auth, body, error } = await parseRequest(request, schema);
|
||||
const { auth, body, error } = await parseRequest(request, reportResultSchema);
|
||||
|
||||
if (error) {
|
||||
return error();
|
||||
@@ -60,3 +30,11 @@ export async function POST(request: Request) {
|
||||
|
||||
return json(data);
|
||||
}
|
||||
|
||||
function convertFilters(filters: any[]) {
|
||||
return filters.reduce((obj, filter) => {
|
||||
obj[filter.name] = filter;
|
||||
|
||||
return obj;
|
||||
}, {});
|
||||
}
|
||||
|
||||
@@ -1,17 +1,11 @@
|
||||
import { z } from 'zod';
|
||||
import { canViewWebsite } from '@/lib/auth';
|
||||
import { unauthorized, json } from '@/lib/response';
|
||||
import { parseRequest } from '@/lib/request';
|
||||
import { getRetention } from '@/queries';
|
||||
import { reportParms, timezoneParam } from '@/lib/schema';
|
||||
import { reportResultSchema } from '@/lib/schema';
|
||||
|
||||
export async function POST(request: Request) {
|
||||
const schema = z.object({
|
||||
...reportParms,
|
||||
timezone: timezoneParam,
|
||||
});
|
||||
|
||||
const { auth, body, error } = await parseRequest(request, schema);
|
||||
const { auth, body, error } = await parseRequest(request, reportResultSchema);
|
||||
|
||||
if (error) {
|
||||
return error();
|
||||
@@ -20,7 +14,6 @@ export async function POST(request: Request) {
|
||||
const {
|
||||
websiteId,
|
||||
dateRange: { startDate, endDate },
|
||||
timezone,
|
||||
} = body;
|
||||
|
||||
if (!(await canViewWebsite(auth, websiteId))) {
|
||||
@@ -30,7 +23,6 @@ export async function POST(request: Request) {
|
||||
const data = await getRetention(websiteId, {
|
||||
startDate: new Date(startDate),
|
||||
endDate: new Date(endDate),
|
||||
timezone,
|
||||
});
|
||||
|
||||
return json(data);
|
||||
|
||||
@@ -1,40 +1,11 @@
|
||||
import { z } from 'zod';
|
||||
import { canViewWebsite } from '@/lib/auth';
|
||||
import { unauthorized, json } from '@/lib/response';
|
||||
import { parseRequest } from '@/lib/request';
|
||||
import { reportParms, timezoneParam } from '@/lib/schema';
|
||||
import { reportResultSchema } from '@/lib/schema';
|
||||
import { getRevenue } from '@/queries/sql/reports/getRevenue';
|
||||
import { getRevenueValues } from '@/queries/sql/reports/getRevenueValues';
|
||||
|
||||
export async function GET(request: Request) {
|
||||
const { auth, query, error } = await parseRequest(request);
|
||||
|
||||
if (error) {
|
||||
return error();
|
||||
}
|
||||
|
||||
const { websiteId, startDate, endDate } = query;
|
||||
|
||||
if (!(await canViewWebsite(auth, websiteId))) {
|
||||
return unauthorized();
|
||||
}
|
||||
|
||||
const data = await getRevenueValues(websiteId, {
|
||||
startDate: new Date(startDate),
|
||||
endDate: new Date(endDate),
|
||||
});
|
||||
|
||||
return json(data);
|
||||
}
|
||||
|
||||
export async function POST(request: Request) {
|
||||
const schema = z.object({
|
||||
currency: z.string(),
|
||||
...reportParms,
|
||||
timezone: timezoneParam,
|
||||
});
|
||||
|
||||
const { auth, body, error } = await parseRequest(request, schema);
|
||||
const { auth, body, error } = await parseRequest(request, reportResultSchema);
|
||||
|
||||
if (error) {
|
||||
return error();
|
||||
@@ -43,7 +14,6 @@ export async function POST(request: Request) {
|
||||
const {
|
||||
websiteId,
|
||||
currency,
|
||||
timezone,
|
||||
dateRange: { startDate, endDate, unit },
|
||||
} = body;
|
||||
|
||||
@@ -55,7 +25,6 @@ export async function POST(request: Request) {
|
||||
startDate: new Date(startDate),
|
||||
endDate: new Date(endDate),
|
||||
unit,
|
||||
timezone,
|
||||
currency,
|
||||
});
|
||||
|
||||
|
||||
@@ -1,16 +1,11 @@
|
||||
import { z } from 'zod';
|
||||
import { canViewWebsite } from '@/lib/auth';
|
||||
import { unauthorized, json } from '@/lib/response';
|
||||
import { parseRequest } from '@/lib/request';
|
||||
import { getUTM } from '@/queries';
|
||||
import { reportParms } from '@/lib/schema';
|
||||
import { reportResultSchema } from '@/lib/schema';
|
||||
|
||||
export async function POST(request: Request) {
|
||||
const schema = z.object({
|
||||
...reportParms,
|
||||
});
|
||||
|
||||
const { auth, body, error } = await parseRequest(request, schema);
|
||||
const { auth, body, error } = await parseRequest(request, reportResultSchema);
|
||||
|
||||
if (error) {
|
||||
return error();
|
||||
@@ -18,7 +13,7 @@ export async function POST(request: Request) {
|
||||
|
||||
const {
|
||||
websiteId,
|
||||
dateRange: { startDate, endDate, timezone },
|
||||
dateRange: { startDate, endDate },
|
||||
} = body;
|
||||
|
||||
if (!(await canViewWebsite(auth, websiteId))) {
|
||||
@@ -28,7 +23,6 @@ export async function POST(request: Request) {
|
||||
const data = await getUTM(websiteId, {
|
||||
startDate: new Date(startDate),
|
||||
endDate: new Date(endDate),
|
||||
timezone,
|
||||
});
|
||||
|
||||
return json(data);
|
||||
|
||||
Reference in New Issue
Block a user