mirror of
https://github.com/jcreek/LivingDexTracker.git
synced 2026-07-13 02:53:45 +00:00
feat(*): Add region-game mappings
This commit is contained in:
@@ -0,0 +1,46 @@
|
|||||||
|
[
|
||||||
|
{
|
||||||
|
"region": "Kanto",
|
||||||
|
"games": ["Red", "Blue", "Yellow", "LG: Pikachu", "LG: Eevee"]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"region": "Johto",
|
||||||
|
"games": ["Gold", "Silver", "Crystal", "HG", "SS"]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"region": "Hoenn",
|
||||||
|
"games": ["Ruby", "Sapphire", "Emerald", "OR", "AS"]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"region": "Sinnoh",
|
||||||
|
"games": ["Diamond", "Pearl", "Platinum", "BD", "SP"]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"region": "Unova",
|
||||||
|
"games": ["Black", "White", "Black2", "White2", "Dream Radar"]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"region": "Kalos",
|
||||||
|
"games": ["X", "Y"]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"region": "Alola",
|
||||||
|
"games": ["Sun", "Moon", "Moon Demo", "US", "UM"]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"region": "Galar",
|
||||||
|
"games": ["Sword", "Shield"]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"region": "Hisui",
|
||||||
|
"games": ["PLA"]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"region": "Paldea",
|
||||||
|
"games": ["Scarlet", "Violet"]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"region": "Unknown",
|
||||||
|
"games": ["Home", "Go"]
|
||||||
|
}
|
||||||
|
]
|
||||||
@@ -0,0 +1,13 @@
|
|||||||
|
import mongoose, { Schema, Document } from 'mongoose';
|
||||||
|
|
||||||
|
export interface RegionGameMapping extends Document {
|
||||||
|
region: string;
|
||||||
|
games: string[];
|
||||||
|
}
|
||||||
|
|
||||||
|
const regionGameMappingSchema = new Schema<RegionGameMapping>({
|
||||||
|
region: String,
|
||||||
|
games: Array<string>
|
||||||
|
});
|
||||||
|
|
||||||
|
export default mongoose.model<RegionGameMapping>('RegionGameMapping', regionGameMappingSchema);
|
||||||
@@ -0,0 +1,25 @@
|
|||||||
|
import RegionGameMappingModel, { type RegionGameMapping } from '$lib/models/RegionGameMapping';
|
||||||
|
|
||||||
|
class RegionGameMappingRepository {
|
||||||
|
async findById(id: string): Promise<RegionGameMapping | null> {
|
||||||
|
return RegionGameMappingModel.findById(id).exec();
|
||||||
|
}
|
||||||
|
|
||||||
|
async findAll(): Promise<RegionGameMapping[]> {
|
||||||
|
return RegionGameMappingModel.find().exec();
|
||||||
|
}
|
||||||
|
|
||||||
|
async create(data: Partial<RegionGameMapping>): Promise<RegionGameMapping> {
|
||||||
|
return RegionGameMappingModel.create(data);
|
||||||
|
}
|
||||||
|
|
||||||
|
async update(id: string, data: Partial<RegionGameMapping>): Promise<RegionGameMapping | null> {
|
||||||
|
return RegionGameMappingModel.findByIdAndUpdate(id, data, { new: true }).exec();
|
||||||
|
}
|
||||||
|
|
||||||
|
async delete(id: string): Promise<void> {
|
||||||
|
await RegionGameMappingModel.findByIdAndDelete(id).exec();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export default RegionGameMappingRepository;
|
||||||
@@ -2,8 +2,11 @@ import { json } from '@sveltejs/kit';
|
|||||||
import { dbConnect, dbDisconnect } from '$lib/utils/db';
|
import { dbConnect, dbDisconnect } from '$lib/utils/db';
|
||||||
import PokedexEntryModel from '$lib/models/PokedexEntry';
|
import PokedexEntryModel from '$lib/models/PokedexEntry';
|
||||||
import PokedexEntryRepository from '$lib/repositories/PokedexEntryRepository';
|
import PokedexEntryRepository from '$lib/repositories/PokedexEntryRepository';
|
||||||
|
import RegionGameMapping from '$lib/models/RegionGameMapping';
|
||||||
|
import RegionGameMappingRepository from '$lib/repositories/RegionGameMappingRepository';
|
||||||
import PokedexMetadataModel from '$lib/models/PokedexMetadata';
|
import PokedexMetadataModel from '$lib/models/PokedexMetadata';
|
||||||
import dex from '$lib/helpers/pokedex.json';
|
import dex from '$lib/helpers/pokedex.json';
|
||||||
|
import RegionGameMappingJson from '$lib/helpers/region-game-mapping.json';
|
||||||
|
|
||||||
// Function to update the lastModified field in the metadata collection
|
// Function to update the lastModified field in the metadata collection
|
||||||
const updateLastModified = async () => {
|
const updateLastModified = async () => {
|
||||||
@@ -23,6 +26,7 @@ export const GET = async () => {
|
|||||||
|
|
||||||
await dbConnect()
|
await dbConnect()
|
||||||
.then(async () => {
|
.then(async () => {
|
||||||
|
// Create pokedex entries
|
||||||
const repo = new PokedexEntryRepository();
|
const repo = new PokedexEntryRepository();
|
||||||
|
|
||||||
dex.forEach(async (pokemon: PokedexEntryModel) => {
|
dex.forEach(async (pokemon: PokedexEntryModel) => {
|
||||||
@@ -30,6 +34,10 @@ export const GET = async () => {
|
|||||||
console.log(`Seeded ${pokemon.pokedexNumber} ${pokemon.pokemon} ${pokemon.form}`);
|
console.log(`Seeded ${pokemon.pokedexNumber} ${pokemon.pokemon} ${pokemon.form}`);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Create region-game mappings
|
||||||
|
const regionGameMappingRepository = new RegionGameMappingRepository();
|
||||||
|
await regionGameMappingRepository.create(RegionGameMappingJson as RegionGameMapping[]);
|
||||||
|
|
||||||
// Update the lastModified field after seeding
|
// Update the lastModified field after seeding
|
||||||
await updateLastModified();
|
await updateLastModified();
|
||||||
})
|
})
|
||||||
|
|||||||
Reference in New Issue
Block a user