mirror of
https://github.com/Drop-OSS/drop.git
synced 2025-11-14 00:31:25 +10:00
almst complete admin ui and initial store designs
This commit is contained in:
56
server/api/v1/admin/game/image.delete.ts
Normal file
56
server/api/v1/admin/game/image.delete.ts
Normal file
@ -0,0 +1,56 @@
|
||||
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.gameId;
|
||||
const imageId = body.imageId;
|
||||
|
||||
if (!gameId || !imageId)
|
||||
throw createError({
|
||||
statusCode: 400,
|
||||
statusMessage: "Missing gameId or imageId in body",
|
||||
});
|
||||
|
||||
const game = await prisma.game.findUnique({
|
||||
where: {
|
||||
id: gameId,
|
||||
},
|
||||
select: {
|
||||
mBannerId: true,
|
||||
mImageLibrary: true,
|
||||
mCoverId: true,
|
||||
},
|
||||
});
|
||||
|
||||
if (!game)
|
||||
throw createError({ statusCode: 400, statusMessage: "Invalid game ID" });
|
||||
|
||||
game.mImageLibrary = game.mImageLibrary.filter((e) => e != imageId);
|
||||
if (game.mBannerId === imageId) {
|
||||
game.mBannerId = game.mImageLibrary[0];
|
||||
}
|
||||
if (game.mCoverId === imageId) {
|
||||
game.mCoverId = game.mImageLibrary[0];
|
||||
}
|
||||
|
||||
const result = await prisma.game.update({
|
||||
where: {
|
||||
id: gameId,
|
||||
},
|
||||
data: {
|
||||
mBannerId: game.mBannerId,
|
||||
mImageLibrary: game.mImageLibrary,
|
||||
mCoverId: game.mCoverId,
|
||||
},
|
||||
select: {
|
||||
mBannerId: true,
|
||||
mImageLibrary: true,
|
||||
mCoverId: true,
|
||||
},
|
||||
});
|
||||
|
||||
return result;
|
||||
});
|
||||
25
server/api/v1/admin/game/index.get.ts
Normal file
25
server/api/v1/admin/game/index.get.ts
Normal file
@ -0,0 +1,25 @@
|
||||
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 query = getQuery(h3);
|
||||
const gameId = query.id?.toString();
|
||||
if (!gameId)
|
||||
throw createError({
|
||||
statusCode: 400,
|
||||
statusMessage: "Missing id in query",
|
||||
});
|
||||
|
||||
const game = await prisma.game.findUnique({
|
||||
where: {
|
||||
id: gameId,
|
||||
},
|
||||
});
|
||||
|
||||
if (!game)
|
||||
throw createError({ statusCode: 404, statusMessage: "Game ID not found" });
|
||||
|
||||
return game;
|
||||
});
|
||||
24
server/api/v1/admin/game/index.patch.ts
Normal file
24
server/api/v1/admin/game/index.patch.ts
Normal file
@ -0,0 +1,24 @@
|
||||
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 id = body.id;
|
||||
if (!id)
|
||||
throw createError({ statusCode: 400, statusMessage: "Missing id in body" });
|
||||
|
||||
const restOfTheBody = { ...body };
|
||||
delete restOfTheBody["id"];
|
||||
|
||||
const newObj = await prisma.game.update({
|
||||
where: {
|
||||
id: id,
|
||||
},
|
||||
data: restOfTheBody,
|
||||
// I would put a select here, but it would be based on the body, and muck up the types
|
||||
});
|
||||
|
||||
return newObj;
|
||||
});
|
||||
25
server/api/v1/games/[id]/index.get.ts
Normal file
25
server/api/v1/games/[id]/index.get.ts
Normal file
@ -0,0 +1,25 @@
|
||||
import prisma from "~/server/internal/db/database";
|
||||
|
||||
export default defineEventHandler(async (h3) => {
|
||||
const userId = await h3.context.session.getUserId(h3);
|
||||
if (!userId) throw createError({ statusCode: 403 });
|
||||
|
||||
const gameId = getRouterParam(h3, "id");
|
||||
if (!gameId)
|
||||
throw createError({
|
||||
statusCode: 400,
|
||||
statusMessage: "Missing gameId in route params (somehow...?)",
|
||||
});
|
||||
|
||||
const game = await prisma.game.findUnique({
|
||||
where: { id: gameId },
|
||||
include: {
|
||||
versions: true,
|
||||
},
|
||||
});
|
||||
|
||||
if (!game)
|
||||
throw createError({ statusCode: 404, statusMessage: "Game not found" });
|
||||
|
||||
return game;
|
||||
});
|
||||
Reference in New Issue
Block a user