Files
elysium/apps/api/src/routes/prestige.ts
T
hikari a3daed1683 feat: initial elysium idle game prototype
Sets up the full monorepo with pnpm workspaces. Includes shared types
package, Hono API with Discord OAuth/JWT auth, Prisma v6 + MongoDB
Atlas, and React + Vite frontend with game loop, five tabs, and
Discord-linked save/load.
2026-03-06 11:26:19 -08:00

64 lines
1.6 KiB
TypeScript

import type { GameState, PrestigeRequest } from "@elysium/types";
import { Hono } from "hono";
import { prisma } from "../db/client.js";
import { authMiddleware } from "../middleware/auth.js";
import {
buildPostPrestigeState,
isEligibleForPrestige,
} from "../services/prestige.js";
export const prestigeRouter = new Hono();
prestigeRouter.use("*", authMiddleware);
prestigeRouter.post("/", async (context) => {
const discordId = context.get("discordId") as string;
const body = await context.req.json<PrestigeRequest>();
const characterName = body.characterName?.trim();
if (!characterName) {
return context.json({ error: "characterName is required" }, 400);
}
const record = await prisma.gameState.findUnique({ where: { discordId } });
if (!record) {
return context.json({ error: "No save found" }, 404);
}
const state = record.state as unknown as GameState;
if (!isEligibleForPrestige(state)) {
return context.json(
{ error: "Not eligible for prestige — collect 1,000,000 total gold first" },
400,
);
}
const { newState, newPrestigeData, runestonesEarned } = buildPostPrestigeState(
state,
characterName,
);
const now = Date.now();
await prisma.gameState.update({
where: { discordId },
data: { state: newState as object, updatedAt: now },
});
await prisma.player.update({
where: { discordId },
data: {
characterName,
totalGoldEarned: 0,
totalClicks: 0,
lastSavedAt: now,
},
});
return context.json({
runestones: runestonesEarned,
newPrestigeCount: newPrestigeData.count,
});
});