mirror of
https://github.com/Drop-OSS/drop.git
synced 2025-11-10 04:22:09 +10:00
41 lines
1.1 KiB
TypeScript
41 lines
1.1 KiB
TypeScript
import prisma from "~/server/internal/db/database";
|
|
|
|
export default defineEventHandler(async (h3) => {
|
|
const user = await h3.context.session.getAdminUser(h3);
|
|
if (!user) 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;
|
|
});
|