const express = require('express'),
      Post = require('../models/post')

module.exports = (() => {
    'use strict';

    const router = express.Router();

    const postProjection = {
      __v: false,
      _id: false
    }

    router.get('/', (req, res) => {
      Post.find({}, (err, posts) => {
        if (err) throw err
        if (!posts) {
          const init = new Post({
            id: 0,
            username: 'ragingbull',
            displayName: 'Raging Bull',
            date: Date.now(),
            title: 'Greetings from California State University, ' +
              'Dominguez Hills in Carson, CA!',
            body: 'This post serves as a placeholder.'
          })

          init.save(err => {
            if (err) throw err
            console.log('Sample post initialized.')
            res.json({ posts: init })
          })
        }
        else {
          console.log('Posts retrieved: ', posts)
          res.json({ posts })
        }
      })
    })

    router.post('/create', (req, res) => {
      
      const newPost = new Post({
        user: req.body.user,
        title: req.body.title,
        body: req.body.body,
        createdOn: new Date
      })
    

      
      
      console.log(req.body);

      // Attempt to create the new user in the database.
      Post.create(newPost, (err) => {
        console.log(newPost)
        if (err) {
            throw err
        }
        res.status(200).send();
      })
    
    })

    router.get('/:id', (req, res) => {
      
          Post.find( Post.findById(req.params.id) ,  (err, result) => {
            console.log('Endpoint: Read Post')
                if(err){
                  console.log("Post record doesn't exist!");
                  res.status(204).send();
                }
                else{
                  console.log('Post found');
                  res.send(JSON.stringify(result));
                }
          })
        })    

    return router;
})
();

@@ -1464,32 +1464,474 @@
  %7D)%0A    %0A    %7D)%0A
+       // Update POST %0A     router.put('/update/:id', (req, res, next) =%3E %7B%0A  %0A    console.log(%22EndPoint : update Post%22);%0A  %0A    Post.update(Post.findById(req.params.id),req.body, (err, result) =%3E %7B%0A  %0A      if (err) %7B%0A        console.log(%22Post record doesn't exist!%22);%0A        res.status(204).send();%0A               %7D%0A      else%7B%0A       %0A        console.log(%22success%22);%0A        res.status(200).send();%0A             %0A          %7D%0A    %7D)%0A    %7D)
 %0A    router.get(
@@ -2388,24 +2388,33 @@
     %7D)    %0A%0A
+        %0A
     return r

Update post