mirror of
https://github.com/umami-software/umami.git
synced 2026-02-04 20:57:17 +01:00
38 lines
900 B
TypeScript
38 lines
900 B
TypeScript
import z from 'zod';
|
|
import { uuid } from '@/lib/crypto';
|
|
import { parseRequest } from '@/lib/request';
|
|
import { json, unauthorized } from '@/lib/response';
|
|
import { anyObjectParam } from '@/lib/schema';
|
|
import { canUpdateEntity } from '@/permissions';
|
|
import { createShare } from '@/queries/prisma';
|
|
|
|
export async function POST(request: Request) {
|
|
const schema = z.object({
|
|
entityId: z.uuid(),
|
|
shareType: z.coerce.number().int(),
|
|
slug: z.string().max(100),
|
|
parameters: anyObjectParam,
|
|
});
|
|
|
|
const { auth, body, error } = await parseRequest(request, schema);
|
|
|
|
if (error) {
|
|
return error();
|
|
}
|
|
|
|
const { entityId, shareType, slug, parameters } = body;
|
|
|
|
if (!(await canUpdateEntity(auth, entityId))) {
|
|
return unauthorized();
|
|
}
|
|
|
|
const share = await createShare({
|
|
id: uuid(),
|
|
entityId,
|
|
shareType,
|
|
slug,
|
|
parameters,
|
|
});
|
|
|
|
return json(share);
|
|
}
|