game version re-ordering

This commit is contained in:
DecDuck
2024-10-14 20:34:23 +11:00
parent 8674ac7211
commit 329c74d3ce
18 changed files with 354 additions and 50 deletions

View File

@ -16,6 +16,19 @@ export default defineEventHandler(async (h3) => {
where: {
id: gameId,
},
include: {
versions: {
orderBy: {
versionIndex: "asc",
},
select: {
versionIndex: true,
versionName: true,
platform: true,
delta: true,
}
},
},
});
if (!game)

View File

@ -0,0 +1,26 @@
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();
const version = body.versionName.toString();
if (!gameId || !version)
throw createError({
statusCode: 400,
statusMessage: "Missing ID or versionName in body",
});
await prisma.gameVersion.delete({
where: {
gameId_versionName: {
gameId: gameId,
versionName: version,
},
},
});
return {};
});

View File

@ -0,0 +1,40 @@
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;
});

View File

@ -10,23 +10,24 @@ export default defineEventHandler(async (h3) => {
const platform = body.platform;
const startup = body.startup;
const setup = body.setup ?? "";
if (
!gameId ||
!versionName ||
!platform ||
!startup
)
const delta = body.delta ?? false;
if (!gameId || !versionName || !platform || (!delta && !startup))
throw createError({
statusCode: 400,
statusMessage:
"Missing id, version, platform, setup or startup from body",
});
const taskId = await libraryManager.importVersion(gameId, versionName, {
platform,
startup,
setup,
});
const taskId = await libraryManager.importVersion(
gameId,
versionName,
{
platform,
startup,
setup,
},
delta
);
if (!taskId)
throw createError({
statusCode: 400,