mirror of
https://github.com/umami-software/umami.git
synced 2026-02-08 06:37:18 +01:00
New admin section.
This commit is contained in:
parent
b78ff3b477
commit
ce1f6c3618
44 changed files with 515 additions and 157 deletions
54
src/app/api/admin/teams/route.ts
Normal file
54
src/app/api/admin/teams/route.ts
Normal file
|
|
@ -0,0 +1,54 @@
|
|||
import { z } from 'zod';
|
||||
import { parseRequest } from '@/lib/request';
|
||||
import { json, unauthorized } from '@/lib/response';
|
||||
import { pagingParams, searchParams } from '@/lib/schema';
|
||||
import { canViewAllTeams } from '@/lib/auth';
|
||||
import { getTeams } from '@/queries/prisma/team';
|
||||
|
||||
export async function GET(request: Request) {
|
||||
const schema = z.object({
|
||||
...pagingParams,
|
||||
...searchParams,
|
||||
});
|
||||
|
||||
const { auth, query, error } = await parseRequest(request, schema);
|
||||
|
||||
if (error) {
|
||||
return error();
|
||||
}
|
||||
|
||||
if (!(await canViewAllTeams(auth))) {
|
||||
return unauthorized();
|
||||
}
|
||||
|
||||
const teams = await getTeams(
|
||||
{
|
||||
include: {
|
||||
_count: {
|
||||
select: {
|
||||
teamUser: true,
|
||||
website: true,
|
||||
},
|
||||
},
|
||||
teamUser: {
|
||||
select: {
|
||||
user: {
|
||||
omit: {
|
||||
password: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
where: {
|
||||
role: 'team-owner',
|
||||
},
|
||||
},
|
||||
},
|
||||
orderBy: {
|
||||
createdAt: 'desc',
|
||||
},
|
||||
},
|
||||
query,
|
||||
);
|
||||
|
||||
return json(teams);
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue