mirror of
https://github.com/Drop-OSS/drop.git
synced 2025-11-09 20:12:10 +10:00
* First iteration on the new PieChart component * #128 Adds new admin home page * Fixes code after merging conflicts * Removes empty file * Uses real data for admin home page, and improves style * Reverts debugging code * Defines missing variable * Caches user stats data for admin home page * Typo * Styles improvements * Invalidates cache on signup/signin * Implements top 5 biggest games * Improves styling * Improves style * Using generateManifest to get the proper size * Reading data from cache * Removes unnecessary import * Improves caching mechanism for game sizes * Removes lint errors * Replaces piechart tooltip with colors in legend * Fixes caching * Fixes caching and slight improvement on pie chart colours * Fixes a few bugs related to caching * Fixes bug where app signin didn't refresh cache * feat: style improvements * fix: lint --------- Co-authored-by: DecDuck <declanahofmeyr@gmail.com>
59 lines
1.3 KiB
TypeScript
59 lines
1.3 KiB
TypeScript
import aclManager from "~/server/internal/acls";
|
|
import prisma from "~/server/internal/db/database";
|
|
import libraryManager from "~/server/internal/library";
|
|
|
|
export default defineEventHandler(async (h3) => {
|
|
const userId = await aclManager.getUserIdACL(h3, ["store:read"]);
|
|
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,
|
|
publishers: {
|
|
select: {
|
|
id: true,
|
|
mName: true,
|
|
mShortDescription: true,
|
|
mLogoObjectId: true,
|
|
},
|
|
},
|
|
developers: {
|
|
select: {
|
|
id: true,
|
|
mName: true,
|
|
mShortDescription: true,
|
|
mLogoObjectId: true,
|
|
},
|
|
},
|
|
tags: true,
|
|
},
|
|
});
|
|
|
|
if (!game)
|
|
throw createError({ statusCode: 404, statusMessage: "Game not found" });
|
|
|
|
const rating = await prisma.gameRating.aggregate({
|
|
where: {
|
|
gameId: game.id,
|
|
},
|
|
_avg: {
|
|
mReviewRating: true,
|
|
},
|
|
_sum: {
|
|
mReviewCount: true,
|
|
},
|
|
});
|
|
|
|
const size = await libraryManager.getGameVersionSize(game.id);
|
|
|
|
return { game, rating, size };
|
|
});
|