Umami is a privacy-first web and product analytics platform. Traffic, campaigns, behavior, conversions, and revenue in one place. No cookies, no surveillance, self-hosted or in the cloud.
TypeScript analyticsaudience-segmentationchartscohort-analysisgoogle-analyticsproduct-analyticsstatisticsuser-journeyweb-analytics
import { z } from 'zod';
import { parseRequest } from '@/lib/request';
import { json, unauthorized } from '@/lib/response';
import { pagingParams, searchParams, sortingParams } from '@/lib/schema';
import { canViewAllTeams } from '@/permissions';
import { getTeams } from '@/queries/prisma/team';
export async function GET(request: Request) {
const schema = z.object({
...pagingParams,
...searchParams,
...sortingParams,
});
const { auth, query, error } = await parseRequest(request, schema);
if (error) {
return error();
}
if (!(await canViewAllTeams(auth))) {
return unauthorized();
}
const teams = await getTeams(
{
include: {
members: {
include: {
user: {
select: {
id: true,
username: true,
},
},
},
},
_count: {
select: {
websites: {
where: { deletedAt: null },
},
members: {
where: {
user: { deletedAt: null },
},
},
},
},
},
orderBy: {
createdAt: 'desc',
},
},
query,
);
return json(teams);
}