Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Domo checkpoint-express #155

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions controllers/notes.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
router.get("/", (req, res) => {
res.send("notes/ GET -> INDEX");
});

router.post("/", (req, res) => {
res.send("notes/ POST -> CREATE");
});
34 changes: 34 additions & 0 deletions controllers/users.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
const Users = require("../models/Users");

module.exports = {
index: (req, res) => {
Users.find({}).then(users => {
res.json(users);
});
}
};


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;
4 changes: 3 additions & 1 deletion db/connection.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
const mongoose = require("mongoose");
mongoose.Promise = Promise;

const mongoURI = "mongodb://localhost/notes-checkpoint";

mongoose.connect("mongodb://localhost/notes-checkpoint", {useNewUrlParser: true});

mongoose.Promise = Promise;

module.exports = mongoose;
8 changes: 7 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
@@ -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
23 changes: 20 additions & 3 deletions models/Note.js
Original file line number Diff line number Diff line change
@@ -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", noteSchema);

module.exports = Users;

module.exports = mongoose.model('Note', noteSchema)
21 changes: 18 additions & 3 deletions models/User.js
Original file line number Diff line number Diff line change
@@ -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", userSchema);

module.exports = Users;