mirror of
https://github.com/Drop-OSS/drop.git
synced 2025-11-14 08:41:15 +10:00
feat: openapi support plus more api validation
This commit is contained in:
@ -1,20 +1,30 @@
|
||||
import { type } from "arktype";
|
||||
import aclManager from "~/server/internal/acls";
|
||||
import prisma from "~/server/internal/db/database";
|
||||
|
||||
export default defineEventHandler(async (h3) => {
|
||||
const DeleteInvite = type({
|
||||
id: "string",
|
||||
});
|
||||
|
||||
export default defineEventHandler<{
|
||||
body: typeof DeleteInvite.infer;
|
||||
}>(async (h3) => {
|
||||
const allowed = await aclManager.allowSystemACL(h3, [
|
||||
"auth:simple:invitation:delete",
|
||||
]);
|
||||
if (!allowed) throw createError({ statusCode: 403 });
|
||||
|
||||
const body = await readBody(h3);
|
||||
const id = body.id;
|
||||
if (!id)
|
||||
const body = DeleteInvite(await readBody(h3));
|
||||
if (body instanceof type.errors) {
|
||||
// hover out.summary to see validation errors
|
||||
console.error(body.summary);
|
||||
|
||||
throw createError({
|
||||
statusCode: 400,
|
||||
statusMessage: "id required for deletion",
|
||||
statusMessage: body.summary,
|
||||
});
|
||||
}
|
||||
|
||||
await prisma.invitation.delete({ where: { id: id } });
|
||||
await prisma.invitation.delete({ where: { id: body.id } });
|
||||
return {};
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user