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

susejm checkpoint #135

Open
wants to merge 1 commit 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
22 changes: 22 additions & 0 deletions controllers/notes.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
const express = require ("express");
const notes = require ("../controllers/notes.js");
const router = express.Router

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










18 changes: 18 additions & 0 deletions controllers/users.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
const express = require ("express");
const mongoose = require ("../controllers/users.js");
const router = express.Router


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





13 changes: 13 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,16 @@
const express = require ("express")
const app = express ()
const notes = require ("../routes/notes.js")
const users = require ("../routes/users.js")
const bodyParser = require('body-parser')

app.use (bodyParser.json())
app.use('notes', Note)
app.use('users', User)




app.listen(3000, () => console.log('app is running'))

// DO NOT REMOVE THIS LINE:
Expand Down
14 changes: 11 additions & 3 deletions models/Note.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
const mongoose = require('../db/connection')
const mongoose = require('../models/Note.js')
const Schema = mongoose.Schema

const noteSchema = new mongoose.Schema({})
const Note = new Schema ({
title : String,
body : String,
author : {
type : Schema.Types.ObjectId,
ref: "User"
}
})

module.exports = mongoose.model('Note', noteSchema)
module.exports = mongoose.model('Note', Schema)
14 changes: 11 additions & 3 deletions models/User.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
const mongoose = require('../db/connection')
const mongoose = require('../models/User.js')
const Schema = mongoose.Schema

const userSchema = new mongoose.Schema({})
const User = new Schema ({
username: String,
email: String,
notes : {
type: Schema.Types.ObejctId,
ref: "Note"
}

module.exports = mongoose.model('User', userSchema)
})
module.exports = mongoose.model('User', Schema)
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@

{

"name": "checkpoint-express-mongoose",
"version": "1.0.0",
"description": "",
Expand Down
11 changes: 11 additions & 0 deletions routes/notes.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
const express = require ("express");
const notesController = require ("../controllers/notes");
const router = express.Router;


router.get("/", notesController.index);
router.get("/notes", notesController.new);
router.get("/notes/note1", notesController.create);


module.exports = notes;
16 changes: 16 additions & 0 deletions routes/users.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
const app = express ();
const usersController = require ("../controllers/users");
const router = express.Router;


router.get("/users", usersController.index);
router.get("/users/user1", usersController.create);








module.exports = users;