mirror of
https://github.com/Drop-OSS/drop.git
synced 2025-11-15 09:11:21 +10:00
game version re-ordering
This commit is contained in:
40
server/api/v1/admin/game/version.post.ts
Normal file
40
server/api/v1/admin/game/version.post.ts
Normal 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;
|
||||
});
|
||||
Reference in New Issue
Block a user