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

express checkpoint #152

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
1 change: 1 addition & 0 deletions controllers/notes.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
const Note = require("../models/Note");
2 changes: 2 additions & 0 deletions controllers/users.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
const User = require("../models/User");
const Note = require("../models/Note");
11 changes: 11 additions & 0 deletions db/seed.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
const mongoose = require("./connection");
const seedData = require("../db/seedData.json")

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

// clear the database of records using both models
Note.deleteMany({}).then(() => {
console.log("deleted all notes");
User.deleteMany({}).then(() => {
console.log("deleted all users");
23 changes: 23 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,26 @@
const express = require("express");
const app = express();
const notesApp = require("./routes/notes");
const usersApp = require("./routes/users");

app.get("/", (req, res) => {
res.send(notesApp);
});
app.get("/notes", (req, res) => {
res.send(usersApp);
});
app.get("/notes/id", (req, res) => {
res.send(notesApp);
});
app.get("/list", (req, res) => {
res.send(usersApp);
});
app.get("/users/id", (req, res) => {
res.send(usersApp);
});



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

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

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

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

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

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