diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 0000000..ff60f54 --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,21 @@ +{ + // Use IntelliSense to learn about possible attributes. + // Hover to view descriptions of existing attributes. + // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 + "version": "0.2.0", + "configurations": [ + { + "type": "node", + "request": "launch", + "name": "Debug with ts-node-dev", + "runtimeExecutable": "npx", + "runtimeArgs": ["ts-node-dev", "--inspect", "--respawn", "src/server.ts"], + "skipFiles": ["/**"], + "env": { + "NODE_ENV": "development" + }, + "console": "integratedTerminal", + "internalConsoleOptions": "neverOpen" + } + ] +} \ No newline at end of file diff --git a/package-lock.json b/package-lock.json index 81947d1..46fd1a6 100644 --- a/package-lock.json +++ b/package-lock.json @@ -3048,7 +3048,6 @@ "resolved": "https://registry.npmjs.org/ts-node-dev/-/ts-node-dev-2.0.0.tgz", "integrity": "sha512-ywMrhCfH6M75yftYvrvNarLEY+SUXtUvU8/0Z6llrHQVBx12GiFk5sStF8UdfE/yfzk9IAq7O5EEbTQsxlBI8w==", "dev": true, - "license": "MIT", "dependencies": { "chokidar": "^3.5.1", "dynamic-dedupe": "^0.3.0", diff --git a/src/server.ts b/src/server.ts index 49e4f3e..2da7dbe 100644 --- a/src/server.ts +++ b/src/server.ts @@ -138,85 +138,31 @@ app.post('/api/auth/login', (req: Request, res: Response) => { // Database connection const dbPromise = open({ - filename: '../pokemon_forms.db', // Adjust path to your database file + filename: './pokemon_forms.db', // Adjust path to your database file driver: sqlite3.Database }); -function processPokemonData(pokemonData: any[]): any[][] { - const pokemonList: any[][] = []; - let current_group: any[] = []; - let current_dex_number = 0; - let current_generation = 0; - let pokemon_forms: any[] = []; - - for (const pokemon of pokemonData) { - if (pokemon.national_dex !== current_dex_number) { - if (pokemon_forms.length > 0) { - for (const form of pokemon_forms) { - current_group.push(form); - if (current_group.length === 30) { - pokemonList.push([...current_group]); - current_group = []; - } - } - pokemon_forms = []; - } - current_dex_number = pokemon.national_dex; - - if (!pokemon.form_name) { - if (current_generation === null || pokemon.generation !== current_generation) { - if (current_group.length > 0) { - while (current_group.length < 30) { - current_group.push(null); - } - pokemonList.push([...current_group]); - current_group = []; - } - current_generation = pokemon.generation || 0; - } - } - } - - pokemon_forms.push(pokemon); - } - - // Handle remaining pokemon forms - for (const form of pokemon_forms) { - current_group.push(form); - if (current_group.length === 30) { - pokemonList.push([...current_group]); - current_group = []; - } - } - - // Handle the last group - if (current_group.length > 0) { - while (current_group.length < 30) { - current_group.push(null); - } - pokemonList.push([...current_group]); - } - - return pokemonList; -} - // Routes app.get('/api/pokemon', async (req, res) => { try { const db = await dbPromise; - const pokemon = await db.all(` - SELECT - pf.national_dex, pf.name, pf.form_name, pf.PFIC, pf.generation, - ps.storable_in_home, m.icon_path, m.name as mark_name - FROM pokemon_forms pf - JOIN pokemon_storage ps ON pf.PFIC = ps.PFIC - LEFT JOIN form_marks fm ON pf.PFIC = fm.pfic - LEFT JOIN marks m ON fm.mark_id = m.id - WHERE ps.storable_in_home = 1 - ORDER BY pf.PFIC + const pokemon_data = await db.all(` + SELECT * + FROM pokemon_forms + WHERE JSON_EXTRACT(data, '$.storable_in_home') == true + GROUP BY json_extract(data, '$.sprite_url') + ORDER BY PFIC `); - - const processedData = processPokemonData(pokemon); + + var processedData: any[] = [] + for (const db_pokemon of pokemon_data) { + const data = JSON.parse(db_pokemon.data) + const pokemon = { + "pfic": db_pokemon.PFIC, + "data": data + } + processedData.push(pokemon) + } res.json(processedData); } catch (err) { console.error('Error fetching pokemon:', err); diff --git a/tsconfig.json b/tsconfig.json index c3cb0b7..d1a8f80 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,7 +1,7 @@ { "compilerOptions": { "target": "es2020", - "module": "commonjs", + "module": "CommonJS", "outDir": "./dist", "rootDir": "./src", "strict": true,