diff --git a/controllers/booksController.js b/controllers/booksController.js deleted file mode 100644 index 0e83e81..0000000 --- a/controllers/booksController.js +++ /dev/null @@ -1,37 +0,0 @@ -const db = require("../models"); - -// Defining methods for the booksController -module.exports = { - findAll: function(req, res) { - db.Book - .find(req.query) - .sort({ date: -1 }) - .then(dbModel => res.json(dbModel)) - .catch(err => res.status(422).json(err)); - }, - findById: function(req, res) { - db.Book - .findById(req.params.id) - .then(dbModel => res.json(dbModel)) - .catch(err => res.status(422).json(err)); - }, - create: function(req, res) { - db.Book - .create(req.body) - .then(dbModel => res.json(dbModel)) - .catch(err => res.status(422).json(err)); - }, - update: function(req, res) { - db.Book - .findOneAndUpdate({ _id: req.params.id }, req.body) - .then(dbModel => res.json(dbModel)) - .catch(err => res.status(422).json(err)); - }, - remove: function(req, res) { - db.Book - .findById({ _id: req.params.id }) - .then(dbModel => dbModel.remove()) - .then(dbModel => res.json(dbModel)) - .catch(err => res.status(422).json(err)); - } -}; diff --git a/models/book.js b/models/book.js deleted file mode 100644 index 58758e2..0000000 --- a/models/book.js +++ /dev/null @@ -1,13 +0,0 @@ -const mongoose = require("mongoose"); -const Schema = mongoose.Schema; - -const bookSchema = new Schema({ - title: { type: String, required: true }, - author: { type: String, required: true }, - synopsis: String, - date: { type: Date, default: Date.now } -}); - -const Book = mongoose.model("Book", bookSchema); - -module.exports = Book; diff --git a/models/index.js b/models/index.js index 9fbc9b1..e54ca7c 100644 --- a/models/index.js +++ b/models/index.js @@ -2,6 +2,6 @@ module.exports = { User: require("./user"), Transaction: require("./transaction"), Stock: require("./stock"), - Book: require("./book"), - SymbolName: require("./symbolName") + SymbolName: require("./symbolName"), + Watchlist: require("./watchlist") }; diff --git a/models/watchlist.js b/models/watchlist.js new file mode 100644 index 0000000..748ef0b --- /dev/null +++ b/models/watchlist.js @@ -0,0 +1,13 @@ +const mongoose = require("mongoose"); +const Schema = mongoose.Schema; + +const watchlistSchema = new Schema({ + user_email: {type: String, required:true}, + symbol: {type: String, required:true} + //date: { type: Date, default: Date.now } + +}); + +const Stock = mongoose.model("Watchlist", watchlistSchema ); + +module.exports = Stock; \ No newline at end of file diff --git a/routes/api/books.js b/routes/api/books.js deleted file mode 100644 index 4553220..0000000 --- a/routes/api/books.js +++ /dev/null @@ -1,16 +0,0 @@ -const router = require("express").Router(); -const booksController = require("../../controllers/booksController"); - -// Matches with "/api/books" -router.route("/") - .get(booksController.findAll) - .post(booksController.create); - -// Matches with "/api/books/:id" -router - .route("/:id") - .get(booksController.findById) - .put(booksController.update) - .delete(booksController.remove); - -module.exports = router;