data(*): Add final data changes

This commit is contained in:
Josh Creek
2026-01-17 23:30:40 +00:00
parent 479b3ae7a0
commit 46351c9af0
29 changed files with 12187 additions and 122 deletions
+26 -2
View File
@@ -4,6 +4,7 @@ import PokedexRepository from '$lib/repositories/PokedexRepository';
import { requireAuth } from '$lib/utils/auth';
import type { RequestEvent } from '@sveltejs/kit';
import { recalculatePokedexMappings } from '$lib/services/PokedexMappingService';
import { resolveDexScopes, setPokedexDexScopes } from '$lib/services/PokedexDexScopeService';
// GET: Get single pokedex by ID
export const GET = async (event: RequestEvent) => {
@@ -71,12 +72,35 @@ export const PUT = async (event: RequestEvent) => {
return json({ error: 'Pokedex not found' }, { status: 404 });
}
const dexScopesProvided = Object.prototype.hasOwnProperty.call(data, 'dexScopes');
const requestedDexScopes =
dexScopesProvided && Array.isArray(data.dexScopes)
? data.dexScopes
: existingPokedex.dexScopes || [];
const resolvedDexScopes = await resolveDexScopes(event.locals.supabase, {
...pokedex,
dexScopes: requestedDexScopes
});
const existingDexScopes = new Set(existingPokedex.dexScopes || []);
const nextDexScopes = new Set(resolvedDexScopes);
const dexScopesChanged =
existingDexScopes.size !== nextDexScopes.size ||
[...existingDexScopes].some((dexId) => !nextDexScopes.has(dexId));
if (dexScopesChanged) {
await setPokedexDexScopes(event.locals.supabase, id, resolvedDexScopes);
pokedex.dexScopes = resolvedDexScopes;
}
// Recalculate pokedex_entries_mapping if configuration changed
// Only recalculate if isFormDex or gameScope actually changed (these are the only fields that affect mapping)
// Only recalculate if isFormDex, gameScope, or dexScopes changed
// Compare the persisted result (pokedex) to existingPokedex to catch changes that repo.update may normalize or default
const configChanged =
pokedex.isFormDex !== existingPokedex.isFormDex ||
pokedex.gameScope !== existingPokedex.gameScope;
pokedex.gameScope !== existingPokedex.gameScope ||
dexScopesChanged;
if (configChanged) {
await recalculatePokedexMappings(event.locals.supabase, id, pokedex);
@@ -3,6 +3,7 @@ import CombinedDataRepository from '$lib/repositories/CombinedDataRepository';
import PokedexRepository from '$lib/repositories/PokedexRepository';
import { getOptionalUserId } from '$lib/utils/auth';
import type { RequestEvent } from '@sveltejs/kit';
import { resolveDexScopes } from '$lib/services/PokedexDexScopeService';
// GET: Get combined data (pokédex entries + catch records) for specific pokédex
export const GET = async (event: RequestEvent) => {
@@ -39,6 +40,7 @@ export const GET = async (event: RequestEvent) => {
// Use pokédex's gameScope as default filter if no manual game filter is set
const effectiveGame = game || pokedex.gameScope || '';
const dexScopes = await resolveDexScopes(event.locals.supabase, pokedex);
const repo = new CombinedDataRepository(event.locals.supabase, userId, pokedexId);
@@ -49,11 +51,12 @@ export const GET = async (event: RequestEvent) => {
limit,
enableForms,
region,
effectiveGame
effectiveGame,
dexScopes
);
// Get total count for pagination
const totalCount = await repo.countCombinedData(enableForms, region, effectiveGame);
const totalCount = await repo.countCombinedData(enableForms, region, effectiveGame, dexScopes);
const totalPages = Math.ceil(totalCount / limit);
return json({