Skip to content

Commit

Permalink
implement first database population b00tc4mp#84
Browse files Browse the repository at this point in the history
  • Loading branch information
Eden23 committed Aug 4, 2024
1 parent 1826dd9 commit eff99a8
Show file tree
Hide file tree
Showing 1,046 changed files with 14,489 additions and 341 deletions.
77 changes: 0 additions & 77 deletions staff/marti-herms/project/Pokemon game/api/index.js

This file was deleted.

1 change: 0 additions & 1 deletion staff/marti-herms/project/Pokemon game/api/pokemon.json

This file was deleted.

5 changes: 0 additions & 5 deletions staff/marti-herms/project/Pokemon game/core/index.js

This file was deleted.

32 changes: 0 additions & 32 deletions staff/marti-herms/project/Pokemon game/core/models.js

This file was deleted.

6 changes: 0 additions & 6 deletions staff/marti-herms/project/Pokemon game/core/package-lock.json

This file was deleted.

94 changes: 94 additions & 0 deletions staff/marti-herms/project/PokemonSD/api/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
import 'dotenv/config'
import express from 'express'

import { mongoose } from 'cor'
import axios from 'axios'

import { Pokemon } from '../core/data/models.js'

import fs from 'fs/promises'

const port = 8080

mongoose.connect('mongodb://127.0.0.1:27017/pokemon')
.then(() => {
return fs.readFile('./db/abomasnow.json')
.then(response => response.json())
.then(abomasnow => {
return Pokemon.create({
data: abomasnow.abilities[0]
})
})

})
.then(() => mongoose.disconnect())
.catch(error => {
console.error(error)

mongoose.disconnect()
})

// api.express()

// api.get('/api/data', async (req, res) => {
// try {
// const apiUrl = 'https://pokeapi.co/api/v2/pokemon?limit=100000&offset=0'

// const response = await axios.get(apiUrl)

// const json = JSON.stringify(response.data)

// res.json(response.data)
// } catch (error) {
// console.error('Error fetching data from API:', error)
// res.status(500).json({ error: 'An error occurred while fetching data.' })
// }
// })

// api.get('/api/pokemon', async (req, res) => {
// const jsonRead = fs.readFileSync('./pokemonList.json', 'utf-8')

// const { results } = JSON.parse(jsonRead)

// const names = results.map(pokemon => pokemon.name)

// const names1 = names.slice(0, 1025)

// names1.forEach(async pokemonName => {
// const apiUrl = `https://pokeapi.co/api/v2/pokemon/${pokemonName}`

// const response = await axios.get(apiUrl)

// const pokemon = response.data

// delete pokemon.base_experience
// delete pokemon.cries
// delete pokemon.game_indices
// delete pokemon.height
// delete pokemon.held_items
// delete pokemon.is_default
// delete pokemon.location_area_encounters
// delete pokemon.order
// delete pokemon.past_abilities
// delete pokemon.past_type
// delete pokemon.species

// const jsonWrite = JSON.stringify(response.data)

// fs.appendFile(`../db/${pokemonName}.json`, jsonWrite, (error) => {
// if (error) throw new Error;

// console.log('It\'s saved!');
// })
// })


// res.send()
// })


// api.listen(port, () => {
// console.log(`Server is running on http://localhost:${port}`)
// })
// })
// .catch (error => console.error(error))
Loading

0 comments on commit eff99a8

Please sign in to comment.