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

Sem Saint-Aubin #28

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
11 changes: 11 additions & 0 deletions controllers/notes.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
const Note = require('../models/Note');
const User = require('../models/User');

let noteController = {
get: (req, res) => {
Note.find({}).then(note => res.json(note));
},

};

module.exports = noteController;
Empty file added controllers/users.js
Empty file.
15 changes: 15 additions & 0 deletions db/seed.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@

const Note = require('../models/Note');

const noteData = require('./seedData.json');


Mern.deleteMany({}).then(() => {
Note.collection.insert(noteData)
.then(myNote => {
console.log(myNote)
})
.catch(err => {
console.log(err)
})
})
10 changes: 9 additions & 1 deletion models/Note.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
const mongoose = require('../db/connection')
const Schema = mongoose.Schema

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

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

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

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