Files
drop/server/api/v1/admin/game/version/index.delete.ts
DecDuck 4f8ea3e4ff Custom readValidatedBody util to return more specific error #69 (#78)
* feat: add readDropValidatedBody w/ special handler for ArkErrors

* fix: lint
2025-06-03 17:40:41 +10:00

35 lines
898 B
TypeScript

import { type } from "arktype";
import { readDropValidatedBody, throwingArktype } from "~/server/arktype";
import aclManager from "~/server/internal/acls";
import prisma from "~/server/internal/db/database";
const DeleteVersion = type({
id: "string",
versionName: "string",
}).configure(throwingArktype);
export default defineEventHandler<{ body: typeof DeleteVersion }>(
async (h3) => {
const allowed = await aclManager.allowSystemACL(h3, [
"game:version:delete",
]);
if (!allowed) throw createError({ statusCode: 403 });
const body = await readDropValidatedBody(h3, DeleteVersion);
const gameId = body.id.toString();
const version = body.versionName.toString();
await prisma.gameVersion.delete({
where: {
gameId_versionName: {
gameId: gameId,
versionName: version,
},
},
});
return {};
},
);