mirror of
https://github.com/Drop-OSS/drop.git
synced 2025-11-14 08:41:15 +10:00
chore: move more admin over to arktype validators
This commit is contained in:
@ -2,11 +2,12 @@ import aclManager from "~/server/internal/acls";
|
||||
import prisma from "~/server/internal/db/database";
|
||||
import objectHandler from "~/server/internal/objects";
|
||||
import { type } from "arktype";
|
||||
import { throwingArktype } from "~/server/arktype";
|
||||
|
||||
const DeleteGameImage = type({
|
||||
gameId: "string",
|
||||
imageId: "string",
|
||||
});
|
||||
}).configure(throwingArktype);
|
||||
|
||||
export default defineEventHandler<{
|
||||
body: typeof DeleteGameImage.infer;
|
||||
@ -14,14 +15,8 @@ export default defineEventHandler<{
|
||||
const allowed = await aclManager.allowSystemACL(h3, ["game:image:delete"]);
|
||||
if (!allowed) throw createError({ statusCode: 403 });
|
||||
|
||||
const body = DeleteGameImage(await readBody(h3));
|
||||
if (body instanceof type.errors) {
|
||||
console.error(h3.path, body.summary);
|
||||
throw createError({
|
||||
statusCode: 400,
|
||||
statusMessage: body.summary,
|
||||
});
|
||||
}
|
||||
const body = await readValidatedBody(h3, DeleteGameImage);
|
||||
|
||||
const gameId = body.gameId;
|
||||
const imageId = body.imageId;
|
||||
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
import aclManager from "~/server/internal/acls";
|
||||
import prisma from "~/server/internal/db/database";
|
||||
|
||||
export default defineEventHandler(async (h3) => {
|
||||
export default defineEventHandler<{ query: { id: string } }>(async (h3) => {
|
||||
const allowed = await aclManager.allowSystemACL(h3, ["game:delete"]);
|
||||
if (!allowed) throw createError({ statusCode: 403 });
|
||||
|
||||
|
||||
@ -3,6 +3,7 @@ import aclManager from "~/server/internal/acls";
|
||||
import prisma from "~/server/internal/db/database";
|
||||
import { handleFileUpload } from "~/server/internal/utils/handlefileupload";
|
||||
|
||||
|
||||
export default defineEventHandler(async (h3) => {
|
||||
const allowed = await aclManager.allowSystemACL(h3, ["game:update"]);
|
||||
if (!allowed) throw createError({ statusCode: 403 });
|
||||
|
||||
@ -1,27 +1,34 @@
|
||||
import { type } from "arktype";
|
||||
import { throwingArktype } from "~/server/arktype";
|
||||
import aclManager from "~/server/internal/acls";
|
||||
import prisma from "~/server/internal/db/database";
|
||||
|
||||
export default defineEventHandler(async (h3) => {
|
||||
const allowed = await aclManager.allowSystemACL(h3, ["game:version:delete"]);
|
||||
if (!allowed) throw createError({ statusCode: 403 });
|
||||
const DeleteVersion = type({
|
||||
id: "string",
|
||||
versionName: "string",
|
||||
}).configure(throwingArktype);
|
||||
|
||||
const body = await readBody(h3);
|
||||
const gameId = body.id.toString();
|
||||
const version = body.versionName.toString();
|
||||
if (!gameId || !version)
|
||||
throw createError({
|
||||
statusCode: 400,
|
||||
statusMessage: "Missing ID or versionName in body",
|
||||
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 readValidatedBody(h3, DeleteVersion);
|
||||
|
||||
const gameId = body.id.toString();
|
||||
const version = body.versionName.toString();
|
||||
|
||||
await prisma.gameVersion.delete({
|
||||
where: {
|
||||
gameId_versionName: {
|
||||
gameId: gameId,
|
||||
versionName: version,
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
await prisma.gameVersion.delete({
|
||||
where: {
|
||||
gameId_versionName: {
|
||||
gameId: gameId,
|
||||
versionName: version,
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
return {};
|
||||
});
|
||||
return {};
|
||||
},
|
||||
);
|
||||
|
||||
@ -1,41 +1,47 @@
|
||||
import { type } from "arktype";
|
||||
import { throwingArktype } from "~/server/arktype";
|
||||
import aclManager from "~/server/internal/acls";
|
||||
import prisma from "~/server/internal/db/database";
|
||||
|
||||
export default defineEventHandler(async (h3) => {
|
||||
const allowed = await aclManager.allowSystemACL(h3, ["game:version:update"]);
|
||||
if (!allowed) throw createError({ statusCode: 403 });
|
||||
const UpdateVersionOrder = type({
|
||||
id: "string",
|
||||
versions: "string[]",
|
||||
}).configure(throwingArktype);
|
||||
|
||||
const body = await readBody(h3);
|
||||
const gameId = body.id?.toString();
|
||||
// We expect an array of the version names for this game
|
||||
const versions: string[] | undefined = body.versions;
|
||||
if (!gameId || !versions || !Array.isArray(versions))
|
||||
throw createError({
|
||||
statusCode: 400,
|
||||
statusMessage: "Missing id, versions or versions is not an array",
|
||||
});
|
||||
export default defineEventHandler<{ body: typeof UpdateVersionOrder }>(
|
||||
async (h3) => {
|
||||
const allowed = await aclManager.allowSystemACL(h3, [
|
||||
"game:version:update",
|
||||
]);
|
||||
if (!allowed) throw createError({ statusCode: 403 });
|
||||
|
||||
const newVersions = await prisma.$transaction(
|
||||
versions.map((versionName, versionIndex) =>
|
||||
prisma.gameVersion.update({
|
||||
where: {
|
||||
gameId_versionName: {
|
||||
gameId: gameId,
|
||||
versionName: versionName,
|
||||
const body = await readValidatedBody(h3, UpdateVersionOrder);
|
||||
const gameId = body.id;
|
||||
// We expect an array of the version names for this game
|
||||
const versions = body.versions;
|
||||
|
||||
const newVersions = await prisma.$transaction(
|
||||
versions.map((versionName, versionIndex) =>
|
||||
prisma.gameVersion.update({
|
||||
where: {
|
||||
gameId_versionName: {
|
||||
gameId: gameId,
|
||||
versionName: versionName,
|
||||
},
|
||||
},
|
||||
},
|
||||
data: {
|
||||
versionIndex: versionIndex,
|
||||
},
|
||||
select: {
|
||||
versionIndex: true,
|
||||
versionName: true,
|
||||
platform: true,
|
||||
delta: true,
|
||||
},
|
||||
}),
|
||||
),
|
||||
);
|
||||
data: {
|
||||
versionIndex: versionIndex,
|
||||
},
|
||||
select: {
|
||||
versionIndex: true,
|
||||
versionName: true,
|
||||
platform: true,
|
||||
delta: true,
|
||||
},
|
||||
}),
|
||||
),
|
||||
);
|
||||
|
||||
return newVersions;
|
||||
});
|
||||
return newVersions;
|
||||
},
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user