feat(pokemon): store official data identity separate from display ID

Add data_id and data_identifier to pokemon schema
Use official data ID as internal route ID for non-event pokemon
Prevent applying fetched data with mismatched ID to existing pokemon
This commit is contained in:
2026-05-04 00:06:22 +08:00
parent 8dfd03f3d2
commit fa06d24826
6 changed files with 103 additions and 44 deletions

View File

@@ -79,6 +79,8 @@ function defaultPokemonStats(): PokemonStats {
}
const pokemonForm = ref({
dataId: null as number | null,
dataIdentifier: '',
id: '',
isEventItem: false,
name: '',
@@ -257,8 +259,22 @@ function mergeFetchedTranslations(fetchedTranslations: TranslationMap | undefine
}
function applyFetchedPokemon(fetchedPokemon: PokemonFetchResult): boolean {
const routePokemonId = Number(routeId.value);
if (
isEditing.value &&
!pokemonForm.value.isEventItem &&
Number.isInteger(routePokemonId) &&
routePokemonId > 0 &&
fetchedPokemon.id !== routePokemonId
) {
message.value = t('pages.pokemon.fetchIdMismatch', { id: fetchedPokemon.id });
return false;
}
pokemonForm.value = {
...pokemonForm.value,
dataId: fetchedPokemon.id,
dataIdentifier: fetchedPokemon.identifier,
id: pokemonForm.value.id.trim() === '' ? String(fetchedPokemon.id) : pokemonForm.value.id,
name: fetchedPokemon.name,
genus: fetchedPokemon.genus,
@@ -295,6 +311,8 @@ async function loadEditor() {
if (isEditing.value) {
const pokemon = await api.pokemonDetail(routeId.value);
pokemonForm.value = {
dataId: pokemon.dataId ?? null,
dataIdentifier: pokemon.dataIdentifier ?? '',
id: String(pokemon.displayId),
isEventItem: pokemon.isEventItem,
name: pokemon.baseName ?? pokemon.name,
@@ -678,6 +696,8 @@ async function savePokemon() {
try {
const payload: PokemonPayload = {
dataId: pokemonForm.value.dataId,
dataIdentifier: pokemonForm.value.dataIdentifier,
displayId: pokemonIdForSave(),
isEventItem: pokemonForm.value.isEventItem,
name: pokemonNameForSave(),