Browse Source

- Updates to work with the new structure

pull/1/head
Dan 1 year ago
parent
commit
37b0944769
  1. 31
      src/server.ts

31
src/server.ts

@ -176,24 +176,17 @@ app.get('/api/pokemon/:pfic/details', async (req, res) => {
const { pfic } = req.params; const { pfic } = req.params;
const details = await db.get(` const details = await db.get(`
SELECT pf.name, pf.form_name, pf.national_dex, pf.generation, SELECT *
ps.storable_in_home, pf.is_baby_form FROM pokemon_forms
FROM pokemon_forms pf WHERE PFIC = ?
LEFT JOIN pokemon_storage ps ON pf.PFIC = ps.PFIC
WHERE pf.PFIC = ?
`, pfic); `, pfic);
const encounters = await db.all(` const data = JSON.parse(details.data)
SELECT g.name as game_name, e.location, e.day, e.time, const pokemon = {
e.dual_slot, e.static_encounter_count, e.static_encounter, "pfic": details.PFIC,
e.extra_text, e.stars, e.rods, e.fishing "data": data
FROM encounters e }
JOIN games g ON e.game_id = g.id res.json(pokemon);
WHERE e.pfic = ?
ORDER BY g.name, e.location
`, pfic);
res.json({ ...details, encounters });
} catch (err) { } catch (err) {
console.error('Error fetching pokemon details:', err); console.error('Error fetching pokemon details:', err);
res.status(500).json({ error: 'Internal server error' }); res.status(500).json({ error: 'Internal server error' });
@ -204,7 +197,7 @@ app.get('/api/plan', authenticateToken, async (req: AuthRequest, res: Response)
try { try {
// Read the efficiency plan file // Read the efficiency plan file
const planData = await fs.readFile( const planData = await fs.readFile(
path.join(__dirname, '../efficiency_plan.json'), path.join(__dirname, '../plan.json'),
'utf-8' 'utf-8'
); );
const efficiencyPlan = JSON.parse(planData); const efficiencyPlan = JSON.parse(planData);
@ -265,8 +258,9 @@ app.get('/api/plan', authenticateToken, async (req: AuthRequest, res: Response)
const debug_pfic = "0010-01-000-0"; const debug_pfic = "0010-01-000-0";
// Enhance the plan with evolution methods and account for caught Pokemon // Enhance the plan with evolution methods and account for caught Pokemon
/*
for (const game of efficiencyPlan) { for (const game of efficiencyPlan) {
for (const pokemon of game.pokemon) { for (const pokemon of game.pokemon.keys()) {
// Set initial catch count // Set initial catch count
pokemon.catch_count = 1; pokemon.catch_count = 1;
if (pokemon.pfic === debug_pfic) { if (pokemon.pfic === debug_pfic) {
@ -308,6 +302,7 @@ app.get('/api/plan', authenticateToken, async (req: AuthRequest, res: Response)
} }
} }
} }
*/
await db.close(); await db.close();
res.json(efficiencyPlan); res.json(efficiencyPlan);

Loading…
Cancel
Save