mirror of
https://github.com/umami-software/umami.git
synced 2026-02-13 00:55:37 +01:00
Converted reports and share routes.
This commit is contained in:
parent
dcac7b7c96
commit
6c9f1ad06b
23 changed files with 574 additions and 5 deletions
73
src/app/api/reports/route.ts
Normal file
73
src/app/api/reports/route.ts
Normal file
|
|
@ -0,0 +1,73 @@
|
|||
import { z } from 'zod';
|
||||
import { pagingParams } from 'lib/schema';
|
||||
import { parseRequest } from 'lib/request';
|
||||
import { canViewTeam, canViewWebsite } from 'lib/auth';
|
||||
import { unauthorized, json } from 'lib/response';
|
||||
import { getReports } from 'queries/prisma/report';
|
||||
|
||||
export async function GET(request: Request) {
|
||||
const schema = z.object({
|
||||
...pagingParams,
|
||||
});
|
||||
|
||||
const { auth, query, error } = await parseRequest(request, schema);
|
||||
|
||||
if (error) {
|
||||
return error();
|
||||
}
|
||||
|
||||
const { page, search, pageSize, websiteId, teamId } = query;
|
||||
const userId = auth.user.id;
|
||||
const filters = {
|
||||
page,
|
||||
pageSize,
|
||||
search,
|
||||
};
|
||||
|
||||
if (
|
||||
(websiteId && !(await canViewWebsite(auth, websiteId))) ||
|
||||
(teamId && !(await canViewTeam(auth, teamId)))
|
||||
) {
|
||||
return unauthorized();
|
||||
}
|
||||
|
||||
const data = await getReports(
|
||||
{
|
||||
where: {
|
||||
OR: [
|
||||
...(websiteId ? [{ websiteId }] : []),
|
||||
...(teamId
|
||||
? [
|
||||
{
|
||||
website: {
|
||||
deletedAt: null,
|
||||
teamId,
|
||||
},
|
||||
},
|
||||
]
|
||||
: []),
|
||||
...(userId && !websiteId && !teamId
|
||||
? [
|
||||
{
|
||||
website: {
|
||||
deletedAt: null,
|
||||
userId,
|
||||
},
|
||||
},
|
||||
]
|
||||
: []),
|
||||
],
|
||||
},
|
||||
include: {
|
||||
website: {
|
||||
select: {
|
||||
domain: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
filters,
|
||||
);
|
||||
|
||||
return json(data);
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue