fix(*): Address PR comments

This commit is contained in:
Josh Creek
2026-01-18 10:41:12 +00:00
parent 46351c9af0
commit 71df0de3df
4 changed files with 15 additions and 12 deletions
@@ -19,10 +19,12 @@ class RegionGameMappingRepository {
}
async update(id: string, data: Partial<RegionGameMapping>): Promise<RegionGameMapping | null> {
void id;
if (!data.region || !data.game) return null;
const normalizedId = Number(id);
const resolvedId = Number.isFinite(normalizedId) ? normalizedId : data.id;
if (typeof resolvedId !== 'number' || !Number.isFinite(resolvedId)) return null;
return {
id: data.id,
id: resolvedId,
region: data.region,
game: data.game
};
+9 -9
View File
@@ -39,20 +39,20 @@ export const POST = async (event: RequestEvent) => {
createdPokedexId = pokedex._id;
createdPokedexName = pokedex.name;
const resolvedDexScopes = await resolveDexScopes(event.locals.supabase, {
...pokedex,
dexScopes: requestedDexScopes
});
await setPokedexDexScopes(event.locals.supabase, pokedex._id, resolvedDexScopes);
pokedex.dexScopes = resolvedDexScopes;
// Populate pokedex_entries_mapping table with expected entries
// Populate dex scopes and pokedex_entries_mapping table with expected entries
try {
const resolvedDexScopes = await resolveDexScopes(event.locals.supabase, {
...pokedex,
dexScopes: requestedDexScopes
});
await setPokedexDexScopes(event.locals.supabase, pokedex._id, resolvedDexScopes);
pokedex.dexScopes = resolvedDexScopes;
await populatePokedexMappings(event.locals.supabase, pokedex._id, pokedex);
} catch (mappingError) {
// Rollback: delete the partially-initialised pokedex to prevent dangling records
console.error(
`Failed to populate pokedex mappings for pokedex id="${createdPokedexId}" name="${createdPokedexName}":`,
`Failed to initialize pokedex id="${createdPokedexId}" name="${createdPokedexName}":`,
mappingError
);
try {
+1 -1
View File
@@ -82,6 +82,7 @@ export const PUT = async (event: RequestEvent) => {
...pokedex,
dexScopes: requestedDexScopes
});
pokedex.dexScopes = resolvedDexScopes;
const existingDexScopes = new Set(existingPokedex.dexScopes || []);
const nextDexScopes = new Set(resolvedDexScopes);
@@ -91,7 +92,6 @@ export const PUT = async (event: RequestEvent) => {
if (dexScopesChanged) {
await setPokedexDexScopes(event.locals.supabase, id, resolvedDexScopes);
pokedex.dexScopes = resolvedDexScopes;
}
// Recalculate pokedex_entries_mapping if configuration changed
@@ -501,6 +501,7 @@ RETURNS TABLE (
updated_at TIMESTAMPTZ
)
SECURITY DEFINER
SET search_path = public, pg_temp
LANGUAGE plpgsql
AS $$
DECLARE