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-express-mongoose-short - David Hutchings #137

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



module.exports = {
index: function(req, res) {
res.send("hello world");
},
show: function(req, res) {
res.send("hello world");
}
};
13 changes: 13 additions & 0 deletions controllers/users.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@

const { Note, User } = require("../models");
//if needed
// const queryOptions = require("../utils/queryOptions");

module.exports = {
index: function(req, res) {
res.send("hello world");
},
show: function(req, res) {
res.send("hello world");
}
};
32 changes: 32 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,36 @@
const express = require("express");
const parser = require('body-parser')
const app = express();
const cors = require('cors')

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


//temp app
// app.get("/", function(req, res) {

// res.send("hello world");

// });

app.use(cors())

// possible first app - redirect to notes - -still crashes nodemon
app.get("/", (req, res) => {
res.redirect("/notes");
});




//not yet set up and not sure if needed
app.get("/notes", require("./routes/notes.js"));
// app.use("/users", require("./routes/users"));


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


// DO NOT REMOVE THIS LINE:
module.exports = app
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 Schema = mongoose.Schema;

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

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

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

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




Loading