Skip to content

Commit

Permalink
chore: update populate db to create a user
Browse files Browse the repository at this point in the history
  • Loading branch information
felixtanhm committed May 8, 2024
1 parent 9f2049c commit c6cc6e6
Showing 1 changed file with 20 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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"
);
Expand Down Expand Up @@ -55,6 +58,8 @@ async function main() {
const detailsRef = await createPokeDetails(newPokeDetails);
await createPokemon(newPokemon, detailsRef);
});

createNewUser();
}

function processPokeData(data) {
Expand Down Expand Up @@ -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");
}

0 comments on commit c6cc6e6

Please sign in to comment.