From e6f6af4310ea21845732a2d385872d5dd3a356d0 Mon Sep 17 00:00:00 2001 From: Domo Date: Wed, 11 Sep 2019 09:51:57 -0400 Subject: [PATCH 1/2] update --- controllers/notes.js | 0 controllers/users.js | 11 +++++++++++ db/connection.js | 4 +++- index.js | 8 +++++++- models/Note.js | 23 ++++++++++++++++++++--- models/User.js | 21 ++++++++++++++++++--- 6 files changed, 59 insertions(+), 8 deletions(-) create mode 100644 controllers/notes.js create mode 100644 controllers/users.js diff --git a/controllers/notes.js b/controllers/notes.js new file mode 100644 index 0000000..e69de29 diff --git a/controllers/users.js b/controllers/users.js new file mode 100644 index 0000000..5493697 --- /dev/null +++ b/controllers/users.js @@ -0,0 +1,11 @@ +const Users = require("../models/Users"); + +module.exports = { + index: (req, res) => { + Users.find({}).then(users => { + res.json(users); + }); + } +}; + + diff --git a/db/connection.js b/db/connection.js index ed144ba..48bf058 100644 --- a/db/connection.js +++ b/db/connection.js @@ -1,7 +1,9 @@ const mongoose = require("mongoose"); +mongoose.Promise = Promise; + +const mongoURI = "mongodb://localhost/checkpoint-express"; mongoose.connect("mongodb://localhost/notes-checkpoint", {useNewUrlParser: true}); -mongoose.Promise = Promise; module.exports = mongoose; diff --git a/index.js b/index.js index 8cdc499..67069f0 100644 --- a/index.js +++ b/index.js @@ -1,4 +1,10 @@ -app.listen(3000, () => console.log('app is running')) +// app.listen(3000, () => console.log('app is running')) +const express = require("express"); +const app = express(); + +app.use(require("./routes/index.js")); + +app.listen(3000, () => console.log("app is running")); // DO NOT REMOVE THIS LINE: module.exports = app diff --git a/models/Note.js b/models/Note.js index 434378a..2b30c61 100644 --- a/models/Note.js +++ b/models/Note.js @@ -1,5 +1,22 @@ -const mongoose = require('../db/connection') +// const mongoose = require('../db/connection') -const noteSchema = new mongoose.Schema({}) +// const noteSchema = new mongoose.Schema({}) + +// module.exports = mongoose.model('Note', noteSchema) + + +const mongoose = require("../db/connection"); + +const noteSchema = new mongoose.Schema({ + title: String, + body: String, + user: { + type: mongoose.Schema.Types.ObjectId, + ref: "Author" + } +}); + +const Users = mongoose.model("Users", usersSchema); + +module.exports = Users; -module.exports = mongoose.model('Note', noteSchema) diff --git a/models/User.js b/models/User.js index 7a0c8b7..96782db 100644 --- a/models/User.js +++ b/models/User.js @@ -1,5 +1,20 @@ -const mongoose = require('../db/connection') +// const mongoose = require('../db/connection') -const userSchema = new mongoose.Schema({}) +// const userSchema = new mongoose.Schema({}) -module.exports = mongoose.model('User', userSchema) +// module.exports = mongoose.model('User', userSchema) + +const mongoose = require("../db/connection"); + +const userSchema = new mongoose.Schema({ + userame: String, + email: String, + note: { + type: mongoose.Schema.Types.ObjectId, + ref: "Notes" + } +}); + +const Users = mongoose.model("Users", usersSchema); + +module.exports = Users; From 359506e0ab4e4e75a13f2e327cd514ef78a1365d Mon Sep 17 00:00:00 2001 From: Domo Date: Wed, 11 Sep 2019 10:12:13 -0400 Subject: [PATCH 2/2] update --- controllers/notes.js | 7 +++++++ controllers/users.js | 23 +++++++++++++++++++++++ db/connection.js | 2 +- models/Note.js | 2 +- models/User.js | 2 +- 5 files changed, 33 insertions(+), 3 deletions(-) diff --git a/controllers/notes.js b/controllers/notes.js index e69de29..bc828da 100644 --- a/controllers/notes.js +++ b/controllers/notes.js @@ -0,0 +1,7 @@ +router.get("/", (req, res) => { + res.send("notes/ GET -> INDEX"); + }); + + router.post("/", (req, res) => { + res.send("notes/ POST -> CREATE"); + }); \ No newline at end of file diff --git a/controllers/users.js b/controllers/users.js index 5493697..bf80d11 100644 --- a/controllers/users.js +++ b/controllers/users.js @@ -9,3 +9,26 @@ module.exports = { }; +router.get("/", (req, res) => { + res.send("Hi from user/ GET -> INDEX"); + }); + + router.post("/", (req, res) => { + res.send("Hi from user/ POST -> CREATE"); + }); + + +// router.get("/:id", (req, res) => { +// console.log(req.params.id); +// res.send(`Hi from user:id=${req.params.id} GET -> SHOW`); +// }); + +// router.put("/:id", (req, res) => { +// res.send(`Hi from user:id=${req.params.id} PUT (UPDATE action)`); +// }); + +// router.delete("/:id", (req, res) => { +// res.send(`Hi from user:id=${req.params.id} DELETE (DESTROY action)`); +// }); + + module.exports = router; \ No newline at end of file diff --git a/db/connection.js b/db/connection.js index 48bf058..48f129c 100644 --- a/db/connection.js +++ b/db/connection.js @@ -1,7 +1,7 @@ const mongoose = require("mongoose"); mongoose.Promise = Promise; -const mongoURI = "mongodb://localhost/checkpoint-express"; +const mongoURI = "mongodb://localhost/notes-checkpoint"; mongoose.connect("mongodb://localhost/notes-checkpoint", {useNewUrlParser: true}); diff --git a/models/Note.js b/models/Note.js index 2b30c61..cf8c8f8 100644 --- a/models/Note.js +++ b/models/Note.js @@ -16,7 +16,7 @@ const noteSchema = new mongoose.Schema({ } }); -const Users = mongoose.model("Users", usersSchema); +const Users = mongoose.model("Users", noteSchema); module.exports = Users; diff --git a/models/User.js b/models/User.js index 96782db..dd18416 100644 --- a/models/User.js +++ b/models/User.js @@ -15,6 +15,6 @@ const userSchema = new mongoose.Schema({ } }); -const Users = mongoose.model("Users", usersSchema); +const Users = mongoose.model("Users", userSchema); module.exports = Users;