Some checks failed
Test and deploy staging / staging (push) Failing after 43s
Run the sveltekit-3 migration and finish its manual tasks:
- Move kit config into the sveltekit() Vite plugin; drop svelte.config.js
- Replace $lib with #lib subpath imports
- Declare env vars in src/env.ts and import them from $app/env/{private,public}
- Consolidate param matchers into src/params.ts
- Use error(status, message), Response.json, refreshAll and goto reset/shallow
- Fall back to a full page load when goto rejects a login return path
Switch from adapter-node to adapter-bun: the build script runs Vite under
Bun (the adapter requires it) and the image starts with `bun ./build`.
Runtime env names (PORT, BODY_SIZE_LIMIT, ADDRESS_HEADER, ...) are unchanged.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
96 lines
2.5 KiB
TypeScript
96 lines
2.5 KiB
TypeScript
import { eq, count } from 'drizzle-orm';
|
|
import { db } from './db';
|
|
import { pokemonProgress } from '#lib/game-tracker/progress.js';
|
|
import {
|
|
games,
|
|
pokemon,
|
|
pokemonGameEntries,
|
|
pokemonGameResearch,
|
|
pokemonDexNumbers,
|
|
pokemonJourneys,
|
|
pokemonMilestones,
|
|
pokemonSeen,
|
|
userEntries,
|
|
userGames,
|
|
catchEmAllSettings
|
|
} from './db/schema';
|
|
|
|
export async function loadPokemonProgress(userId?: string) {
|
|
const [
|
|
gameRows,
|
|
entries,
|
|
research,
|
|
dex,
|
|
caught,
|
|
seen,
|
|
journeys,
|
|
milestones,
|
|
selected,
|
|
settings,
|
|
totals
|
|
] = await Promise.all([
|
|
db.select({ id: games.id, name: games.name, slug: games.slug }).from(games),
|
|
db
|
|
.select({
|
|
id: pokemonGameEntries.id,
|
|
gameId: pokemonGameEntries.gameId,
|
|
pokemonId: pokemonGameEntries.pokemonId,
|
|
availability: pokemonGameEntries.availability
|
|
})
|
|
.from(pokemonGameEntries),
|
|
db
|
|
.select({ gameId: pokemonGameResearch.gameId, regions: pokemonGameResearch.regions })
|
|
.from(pokemonGameResearch),
|
|
db
|
|
.select({ gameId: pokemonDexNumbers.gameId, pokemonId: pokemonDexNumbers.pokemonId })
|
|
.from(pokemonDexNumbers),
|
|
userId
|
|
? db
|
|
.select({ id: userEntries.pokemonGameEntryId })
|
|
.from(userEntries)
|
|
.where(eq(userEntries.userId, userId))
|
|
: [],
|
|
userId
|
|
? db
|
|
.select({ gameId: pokemonSeen.gameId, pokemonId: pokemonSeen.pokemonId })
|
|
.from(pokemonSeen)
|
|
.where(eq(pokemonSeen.userId, userId))
|
|
: [],
|
|
userId
|
|
? db
|
|
.select({ gameId: pokemonJourneys.gameId, completed: pokemonJourneys.completed })
|
|
.from(pokemonJourneys)
|
|
.where(eq(pokemonJourneys.userId, userId))
|
|
: [],
|
|
userId ? db.select().from(pokemonMilestones).where(eq(pokemonMilestones.userId, userId)) : [],
|
|
userId
|
|
? db.select({ gameId: userGames.gameId }).from(userGames).where(eq(userGames.userId, userId))
|
|
: [],
|
|
userId
|
|
? db
|
|
.select({ id: catchEmAllSettings.id })
|
|
.from(catchEmAllSettings)
|
|
.where(eq(catchEmAllSettings.userId, userId))
|
|
: [],
|
|
db.select({ count: count() }).from(pokemon)
|
|
]);
|
|
const configured = settings.length > 0 || selected.length > 0;
|
|
const ids = new Set(selected.map((g) => g.gameId));
|
|
const regions = new Map(research.map((r) => [r.gameId, r.regions]));
|
|
return {
|
|
...pokemonProgress({
|
|
games: gameRows
|
|
.filter((g) => !configured || ids.has(g.id))
|
|
.map((g) => ({ ...g, regions: regions.get(g.id) ?? [] })),
|
|
entries,
|
|
dex,
|
|
caughtIds: caught.map((c) => c.id),
|
|
seen,
|
|
journeys,
|
|
milestones,
|
|
speciesTotal: totals[0].count
|
|
}),
|
|
configured
|
|
};
|
|
}
|