mirror of
https://github.com/umami-software/umami.git
synced 2026-02-07 06:07:17 +01:00
Merge branch 'dev' into jajaja
# Conflicts: # package.json # pnpm-lock.yaml
This commit is contained in:
commit
a7dad20d8a
15 changed files with 617 additions and 63 deletions
|
|
@ -28,8 +28,8 @@ export async function GET(request: Request, { params }: { params: Promise<{ team
|
|||
|
||||
export async function POST(request: Request, { params }: { params: Promise<{ teamId: string }> }) {
|
||||
const schema = z.object({
|
||||
name: z.string().max(50),
|
||||
accessCode: z.string().max(50),
|
||||
name: z.string().max(50).optional(),
|
||||
accessCode: z.string().max(50).optional(),
|
||||
});
|
||||
|
||||
const { auth, body, error } = await parseRequest(request, schema);
|
||||
|
|
|
|||
|
|
@ -33,7 +33,7 @@ export async function POST(
|
|||
const schema = z.object({
|
||||
name: z.string(),
|
||||
domain: z.string(),
|
||||
shareId: z.string().regex(SHARE_ID_REGEX).nullable(),
|
||||
shareId: z.string().regex(SHARE_ID_REGEX).nullable().optional(),
|
||||
});
|
||||
|
||||
const { auth, body, error } = await parseRequest(request, schema);
|
||||
|
|
|
|||
|
|
@ -5,14 +5,6 @@ import { getAllowedUnits, getMinimumUnit } from '@/lib/date';
|
|||
import { checkAuth } from '@/lib/auth';
|
||||
import { getWebsiteDateRange } from '@/queries';
|
||||
|
||||
export async function getJsonBody(request: Request) {
|
||||
try {
|
||||
return await request.clone().json();
|
||||
} catch {
|
||||
return undefined;
|
||||
}
|
||||
}
|
||||
|
||||
export async function parseRequest(
|
||||
request: Request,
|
||||
schema?: ZodSchema,
|
||||
|
|
@ -24,15 +16,6 @@ export async function parseRequest(
|
|||
let error: () => void | undefined;
|
||||
let auth = null;
|
||||
|
||||
const getErrorMessages = (error: z.ZodError) => {
|
||||
return Object.entries(error.format())
|
||||
.map(([key, value]) => {
|
||||
const messages = (value as any)._errors;
|
||||
return messages ? `${key}: ${messages.join(', ')}` : null;
|
||||
})
|
||||
.filter(Boolean);
|
||||
};
|
||||
|
||||
if (schema) {
|
||||
const isGet = request.method === 'GET';
|
||||
const result = schema.safeParse(isGet ? query : body);
|
||||
|
|
@ -57,6 +40,14 @@ export async function parseRequest(
|
|||
return { url, query, body, auth, error };
|
||||
}
|
||||
|
||||
export async function getJsonBody(request: Request) {
|
||||
try {
|
||||
return await request.clone().json();
|
||||
} catch {
|
||||
return undefined;
|
||||
}
|
||||
}
|
||||
|
||||
export async function getRequestDateRange(query: Record<string, any>) {
|
||||
const { websiteId, startAt, endAt, unit } = query;
|
||||
|
||||
|
|
@ -96,3 +87,13 @@ export function getRequestFilters(query: Record<string, any>) {
|
|||
return obj;
|
||||
}, {});
|
||||
}
|
||||
|
||||
export function getErrorMessages(error: z.ZodError) {
|
||||
return Object.entries(error.format())
|
||||
.flatMap(([key, value]) => {
|
||||
if (key === '_errors') {
|
||||
return value;
|
||||
}
|
||||
})
|
||||
.filter(Boolean);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue