mirror of
https://github.com/umami-software/umami.git
synced 2026-02-05 21:27:20 +01:00
Converted admin, auth, me and realtime routes.
This commit is contained in:
parent
6c9f1ad06b
commit
5205551ca8
25 changed files with 346 additions and 7 deletions
39
src/app/api/admin/users/route.ts
Normal file
39
src/app/api/admin/users/route.ts
Normal file
|
|
@ -0,0 +1,39 @@
|
|||
import { z } from 'zod';
|
||||
import { parseRequest } from 'lib/request';
|
||||
import { json, unauthorized } from 'lib/response';
|
||||
import { pagingParams } from 'lib/schema';
|
||||
import { canViewUsers } from 'lib/auth';
|
||||
import { getUsers } from 'queries/prisma/user';
|
||||
|
||||
export async function GET(request: Request) {
|
||||
const schema = z.object({
|
||||
...pagingParams,
|
||||
});
|
||||
|
||||
const { auth, query, error } = await parseRequest(request, schema);
|
||||
|
||||
if (error) {
|
||||
return error();
|
||||
}
|
||||
|
||||
if (!(await canViewUsers(auth))) {
|
||||
return unauthorized();
|
||||
}
|
||||
|
||||
const users = await getUsers(
|
||||
{
|
||||
include: {
|
||||
_count: {
|
||||
select: {
|
||||
websiteUser: {
|
||||
where: { deletedAt: null },
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
query,
|
||||
);
|
||||
|
||||
return json(users);
|
||||
}
|
||||
87
src/app/api/admin/websites/route.ts
Normal file
87
src/app/api/admin/websites/route.ts
Normal file
|
|
@ -0,0 +1,87 @@
|
|||
import { z } from 'zod';
|
||||
import { parseRequest } from 'lib/request';
|
||||
import { json, unauthorized } from 'lib/response';
|
||||
import { pagingParams } from 'lib/schema';
|
||||
import { canViewAllWebsites } from 'lib/auth';
|
||||
import { getWebsites } from 'queries/prisma/website';
|
||||
import { ROLES } from 'lib/constants';
|
||||
|
||||
export async function GET(request: Request) {
|
||||
const schema = z.object({
|
||||
...pagingParams,
|
||||
});
|
||||
|
||||
const { auth, query, error } = await parseRequest(request, schema);
|
||||
|
||||
if (error) {
|
||||
return error();
|
||||
}
|
||||
|
||||
if (!(await canViewAllWebsites(auth))) {
|
||||
return unauthorized();
|
||||
}
|
||||
|
||||
const { userId, includeOwnedTeams, includeAllTeams } = query;
|
||||
|
||||
const websites = await getWebsites(
|
||||
{
|
||||
where: {
|
||||
OR: [
|
||||
...(userId && [{ userId }]),
|
||||
...(userId && includeOwnedTeams
|
||||
? [
|
||||
{
|
||||
team: {
|
||||
deletedAt: null,
|
||||
teamUser: {
|
||||
some: {
|
||||
role: ROLES.teamOwner,
|
||||
userId,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
]
|
||||
: []),
|
||||
...(userId && includeAllTeams
|
||||
? [
|
||||
{
|
||||
team: {
|
||||
deletedAt: null,
|
||||
teamUser: {
|
||||
some: {
|
||||
userId,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
]
|
||||
: []),
|
||||
],
|
||||
},
|
||||
include: {
|
||||
user: {
|
||||
select: {
|
||||
username: true,
|
||||
id: true,
|
||||
},
|
||||
},
|
||||
team: {
|
||||
where: {
|
||||
deletedAt: null,
|
||||
},
|
||||
include: {
|
||||
teamUser: {
|
||||
where: {
|
||||
role: ROLES.teamOwner,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
query,
|
||||
);
|
||||
|
||||
return json(websites);
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue