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

Checkpoint 2 finished #143

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

// basic export index the model
module.exports = {
index: (req, res) => {
Note.find({}).then(notes => {
res.json(notes);
});
},
showNotes: (req, res) => {
Note.findOne({}).then(notes => res.json(notes));
},
emailNotes: (req, res) => {
Person.findOne({ author: req.params.email }).then(notes =>
res.json(notes))
}
};
14 changes: 14 additions & 0 deletions controllers/users.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
const User = require("../models/User");

// basic export index the model
module.exports = {
showUsers: (req, res) => {
User.find({}).then(users => {
res.json(users);
});
},
userName: (req, res) => {
User.findOne({ author: req.params.username }).then(notes =>
res.json(notes))
}
};
17 changes: 17 additions & 0 deletions db/seed.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
const mongoose = require("./connection");

const Notes = require("../models/Note");
const Users = require("../models/User");

// const notesSeedData = no seed data
// const usersSeedData = no seed data

Users.deleteMany({}).then(() => {
Users.create(usersSeedData).then(users =>
console.log(users))
})

Notes.deleteMany({}).then(() => {
Notes.create(notesSeedData).then(notes =>
console.log(notes))
})
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 parser = require('body-parser');

const notesRouter = require('./routes/notes');
const usersRouter = require('./routes/users');

app.use(parser.urlencoded({extended: true}));
app.use(parser.json());

app.use('/api/notes', notesRouter);
app.use('/api/users', usersRouter);

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

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

const noteSchema = new mongoose.Schema({})
const noteSchema = new mongoose.Schema({
title: String,
body: String,
// not sure how to reference a schema outside of the file
// author:[User]
})

module.exports = mongoose.model('Note', noteSchema)
const Note = mongoose.model('Note', noteSchema)

module.exports = Note
11 changes: 9 additions & 2 deletions models/User.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
const mongoose = require('../db/connection')

const userSchema = new mongoose.Schema({})
const userSchema = new mongoose.Schema({
username: String,
email: String,
// Again not sure how to reference a schema in a different file
// notes:[Note]
})

module.exports = mongoose.model('User', userSchema)
const User = mongoose.model('User',userSchema)

module.exports = User
Loading