ga-wdi-exercises/project4

Still can't seed my data

Closed this issue · 0 comments

seeds.js

const birthdayPost =
[
  {
    name: "Martha",
    idea: "Backwards Party",
    ages: "5-12",
    gender: "Both",
    image: "https://images.pexels.com/photos/39363/gift-made-package-loop-39363.jpeg?w=940&h=650&auto=compress&cs=tinysrgb",
    description: "Why not do everything backwards? You can make it really fun by sending out thank you cards as invitations, having the birthday cake first, or even making the kids say everyone's name backwards"
  },
  {
    name: "Casey",
    idea: "Tea Party",
    ages: "3-8",
    gender: "girls",
    image: "https://images.pexels.com/photos/42322/tea-tea-time-person-summer-42322.jpeg?h=350&auto=compress&cs=tinysrgb",
    description: "Have a tea party where all of the girls can dress up and have tea with cake. Make everything fancy with soothing music and nice decorations. This party is sure to be a hit!"
  }
]
const birthdayComment = [
  {
    name: "Tiffany",
    idea: "Backwards Party",
    comment: "I really love this idea! It's so original"
  },
  {
    name: "Jason",
    idea: "Backwards Party",
    comment: "We did this for our son and everyone had a blast"
  }
]

var mongoose = require("./connection")

var BirthdayPost = mongoose.model("BirthdayPost")
var BirthdayComment = mongoose.model("BirthdayComment")

BirthdayPost.remove({}).then(function()  {
  BirthdayPost.collection.insert(birthdayPost).then(function() {

    process.exit()
  })
})


BirthdayComment.remove({}).then(function() {
  BirthdayComment.collection.insert(birthdayComment).then(function() {
    process.exit()
  })
})

**connection.js**

// `use strict`;
var mongoose = require("mongoose")
var schema = mongoose.Schema
mongoose.connect("mongodb://localhost/birthday")

var BirthdayCommentSchema = new mongoose.Schema({
  name: String,
  idea: String,
  comment: String
})
var BirthdayPostSchema = new mongoose.Schema({
  name: String,
  idea: String,
  ages: String,
  gender: String,
  image: String,
  description: String,
  comments: [BirthdayCommentSchema]
}
)
mongoose.model("BirthdayPost", BirthdayPostSchema)
mongoose.model("BirthdayComment", BirthdayCommentSchema)


module.exports = mongoose

module.exports = mongoose.model("BirthdayPost", BirthdayPostSchema)

**server.js**
‘use strict’
//
var express = require(`express`);
var mongoose = require(`mongoose`);
var bodyParser = require(`body-parser`);
var mongoose= require("../db/connection");
//
var app = express();
var router = express.Router();
//
//
// var port = process.env.API_PORT || 3001;
//
app.use(bodyParser.urlencoded({ extended: true }));
app.use(bodyParser.json());
//
// // router.get(‘/’, function(req, res) {
// //  res.json({ message: ‘API Initialized!’});
// // });
//
// app.use(‘/api’, router);
app.get("/api/posts", function(req, res){
  BirthdayPost.find({}).then(function(posts){
    res.json(birthdayPosts)
  });
});

app.get("/api/posts/:name", function(req, res){
  BirthdayPost.findOne({name: req.params.name}).then(function(post){
    res.json(post)
  });
});

app.listen(port, function() {
 console.log(`api running on port ${port}`);
});