mirror of
https://github.com/Drop-OSS/drop.git
synced 2025-11-15 17:21:13 +10:00
feat(acls): added backend acls
This commit is contained in:
43
server/api/v1/admin/game/version/index.patch.ts
Normal file
43
server/api/v1/admin/game/version/index.patch.ts
Normal file
@ -0,0 +1,43 @@
|
||||
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 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",
|
||||
});
|
||||
|
||||
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,
|
||||
}
|
||||
})
|
||||
)
|
||||
);
|
||||
|
||||
return newVersions;
|
||||
});
|
||||
Reference in New Issue
Block a user