Skip to content

Commit

Permalink
feat: load user state
Browse files Browse the repository at this point in the history
  • Loading branch information
felixtanhm committed May 8, 2024
1 parent 588a41c commit eda6439
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 30 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
const axios = require("axios");
const Pokemons = require("../models/pokemons");
const PokeDetails = require("../models/pokeDetails");

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
const Users = require("../models/users");

exports.getUser = async function (req, res, next) {
try {
const currUser = await Users.findOne({ email: "[email protected]" })
.populate("favorites")
.exec();

res.status(200).json(currUser);
} catch (error) {
return next(error);
}
};

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,14 @@ const Schema = mongoose.Schema;
const UserSchema = new Schema({
name: { type: String, required: true },
email: { type: String, required: true },
favorites: {
type: [Schema.Types.ObjectId],
ref: "Pokemon",
default: () => {
return null;
},
},

created_at: { type: Date, default: Date.now() },
last_modified: { type: Date, default: Date.now() },
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ 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");
Expand Down Expand Up @@ -109,11 +108,6 @@ async function createNewUser() {
email: "[email protected]",
});

const newFavorites = new Favorites({
user: newUser,
});

await newUser.save();
await newFavorites.save();
console.log("Initial User Created");
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
var express = require('express');
var express = require("express");
var router = express.Router();
const userController = require("../controllers/userController");

/* GET users listing. */
router.get('/', function(req, res, next) {
res.send('respond with a resource');
});
router.get("/", userController.getUser);

module.exports = router;

0 comments on commit eda6439

Please sign in to comment.