-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: update populate db to create a user
- Loading branch information
1 parent
9f2049c
commit c6cc6e6
Showing
1 changed file
with
20 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,6 +10,8 @@ const userArgs = process.argv.slice(2); | |
|
||
const Pokemons = require("./models/pokemons"); | ||
const PokeDetails = require("./models/pokeDetails"); | ||
const Favorites = require("./models/favorites"); | ||
const Users = require("./models/users"); | ||
|
||
const mongoose = require("mongoose"); | ||
mongoose.set("strictQuery", false); | ||
|
@@ -22,6 +24,7 @@ async function main() { | |
console.log("Debug: About to connect"); | ||
await mongoose.connect(mongoDB); | ||
console.log("Debug: Should be connected?"); | ||
|
||
const response = await axios.get( | ||
"https://pokeapi.co/api/v2/pokemon/?limit=151" | ||
); | ||
|
@@ -55,6 +58,8 @@ async function main() { | |
const detailsRef = await createPokeDetails(newPokeDetails); | ||
await createPokemon(newPokemon, detailsRef); | ||
}); | ||
|
||
createNewUser(); | ||
} | ||
|
||
function processPokeData(data) { | ||
|
@@ -97,3 +102,18 @@ async function createPokemon(newPokemon, detailsRef) { | |
console.log(`Pokemon: ${pokemon.name}`); | ||
console.log(`-------------`); | ||
} | ||
|
||
async function createNewUser() { | ||
const newUser = new Users({ | ||
name: "Felix Tan", | ||
email: "[email protected]", | ||
}); | ||
|
||
const newFavorites = new Favorites({ | ||
user: newUser, | ||
}); | ||
|
||
await newUser.save(); | ||
await newFavorites.save(); | ||
console.log("Initial User Created"); | ||
} |