mirror of
https://github.com/jcreek/LivingDexTracker.git
synced 2026-07-13 02:53:45 +00:00
fix(*): Address PR comments
This commit is contained in:
@@ -19,10 +19,12 @@ class RegionGameMappingRepository {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async update(id: string, data: Partial<RegionGameMapping>): Promise<RegionGameMapping | null> {
|
async update(id: string, data: Partial<RegionGameMapping>): Promise<RegionGameMapping | null> {
|
||||||
void id;
|
|
||||||
if (!data.region || !data.game) return null;
|
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 {
|
return {
|
||||||
id: data.id,
|
id: resolvedId,
|
||||||
region: data.region,
|
region: data.region,
|
||||||
game: data.game
|
game: data.game
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -39,6 +39,8 @@ export const POST = async (event: RequestEvent) => {
|
|||||||
createdPokedexId = pokedex._id;
|
createdPokedexId = pokedex._id;
|
||||||
createdPokedexName = pokedex.name;
|
createdPokedexName = pokedex.name;
|
||||||
|
|
||||||
|
// Populate dex scopes and pokedex_entries_mapping table with expected entries
|
||||||
|
try {
|
||||||
const resolvedDexScopes = await resolveDexScopes(event.locals.supabase, {
|
const resolvedDexScopes = await resolveDexScopes(event.locals.supabase, {
|
||||||
...pokedex,
|
...pokedex,
|
||||||
dexScopes: requestedDexScopes
|
dexScopes: requestedDexScopes
|
||||||
@@ -46,13 +48,11 @@ export const POST = async (event: RequestEvent) => {
|
|||||||
await setPokedexDexScopes(event.locals.supabase, pokedex._id, resolvedDexScopes);
|
await setPokedexDexScopes(event.locals.supabase, pokedex._id, resolvedDexScopes);
|
||||||
pokedex.dexScopes = resolvedDexScopes;
|
pokedex.dexScopes = resolvedDexScopes;
|
||||||
|
|
||||||
// Populate pokedex_entries_mapping table with expected entries
|
|
||||||
try {
|
|
||||||
await populatePokedexMappings(event.locals.supabase, pokedex._id, pokedex);
|
await populatePokedexMappings(event.locals.supabase, pokedex._id, pokedex);
|
||||||
} catch (mappingError) {
|
} catch (mappingError) {
|
||||||
// Rollback: delete the partially-initialised pokedex to prevent dangling records
|
// Rollback: delete the partially-initialised pokedex to prevent dangling records
|
||||||
console.error(
|
console.error(
|
||||||
`Failed to populate pokedex mappings for pokedex id="${createdPokedexId}" name="${createdPokedexName}":`,
|
`Failed to initialize pokedex id="${createdPokedexId}" name="${createdPokedexName}":`,
|
||||||
mappingError
|
mappingError
|
||||||
);
|
);
|
||||||
try {
|
try {
|
||||||
|
|||||||
@@ -82,6 +82,7 @@ export const PUT = async (event: RequestEvent) => {
|
|||||||
...pokedex,
|
...pokedex,
|
||||||
dexScopes: requestedDexScopes
|
dexScopes: requestedDexScopes
|
||||||
});
|
});
|
||||||
|
pokedex.dexScopes = resolvedDexScopes;
|
||||||
|
|
||||||
const existingDexScopes = new Set(existingPokedex.dexScopes || []);
|
const existingDexScopes = new Set(existingPokedex.dexScopes || []);
|
||||||
const nextDexScopes = new Set(resolvedDexScopes);
|
const nextDexScopes = new Set(resolvedDexScopes);
|
||||||
@@ -91,7 +92,6 @@ export const PUT = async (event: RequestEvent) => {
|
|||||||
|
|
||||||
if (dexScopesChanged) {
|
if (dexScopesChanged) {
|
||||||
await setPokedexDexScopes(event.locals.supabase, id, resolvedDexScopes);
|
await setPokedexDexScopes(event.locals.supabase, id, resolvedDexScopes);
|
||||||
pokedex.dexScopes = resolvedDexScopes;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Recalculate pokedex_entries_mapping if configuration changed
|
// Recalculate pokedex_entries_mapping if configuration changed
|
||||||
|
|||||||
@@ -501,6 +501,7 @@ RETURNS TABLE (
|
|||||||
updated_at TIMESTAMPTZ
|
updated_at TIMESTAMPTZ
|
||||||
)
|
)
|
||||||
SECURITY DEFINER
|
SECURITY DEFINER
|
||||||
|
SET search_path = public, pg_temp
|
||||||
LANGUAGE plpgsql
|
LANGUAGE plpgsql
|
||||||
AS $$
|
AS $$
|
||||||
DECLARE
|
DECLARE
|
||||||
|
|||||||
Reference in New Issue
Block a user