Skip to content

armgit / umami

Public Imported from GitHub
0

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.

fix zod validations and prisma query for admin teams

Francis Cao9fb38f6970be
diff --git a/src/app/api/admin/teams/route.ts b/src/app/api/admin/teams/route.ts
index fa203a299..ceb16ab11 100644
--- a/src/app/api/admin/teams/route.ts
+++ b/src/app/api/admin/teams/route.ts
@@ -24,22 +24,26 @@ export async function GET(request: Request) {
const teams = await getTeams(
{
include: {
- _count: {
- select: {
- members: true,
- websites: true,
- },
- },
members: {
- select: {
+ include: {
user: {
- omit: {
- password: true,
+ select: {
+ id: true,
+ username: true,
},
},
},
- where: {
- role: 'team-owner',
+ },
+ _count: {
+ select: {
+ websites: {
+ where: { deletedAt: null },
+ },
+ members: {
+ where: {
+ user: { deletedAt: null },
+ },
+ },
},
},
},
diff --git a/src/app/api/reports/route.ts b/src/app/api/reports/route.ts
index ec8a4d239..123a7e66a 100644
--- a/src/app/api/reports/route.ts
+++ b/src/app/api/reports/route.ts
@@ -1,6 +1,6 @@
import { z } from 'zod';
import { uuid } from '@/lib/crypto';
-import { pagingParams, reportSchema } from '@/lib/schema';
+import { pagingParams, reportSchema, reportTypeParam } from '@/lib/schema';
import { parseRequest } from '@/lib/request';
import { canViewWebsite, canUpdateWebsite } from '@/permissions';
import { unauthorized, json } from '@/lib/response';
@@ -9,7 +9,7 @@ import { getReports, createReport } from '@/queries/prisma';
export async function GET(request: Request) {
const schema = z.object({
websiteId: z.uuid(),
- type: z.string().optional(),
+ type: reportTypeParam.optional(),
...pagingParams,
});
diff --git a/src/app/api/users/[userId]/route.ts b/src/app/api/users/[userId]/route.ts
index fbb794746..c15b4b71b 100644
--- a/src/app/api/users/[userId]/route.ts
+++ b/src/app/api/users/[userId]/route.ts
@@ -26,9 +26,9 @@ export async function GET(request: Request, { params }: { params: Promise<{ user
export async function POST(request: Request, { params }: { params: Promise<{ userId: string }> }) {
const schema = z.object({
- username: z.string().max(255),
+ username: z.string().max(255).optional(),
password: z.string().max(255).optional(),
- role: userRoleParam,
+ role: userRoleParam.optional(),
});
const { auth, body, error } = await parseRequest(request, schema);