"use strict";
let mongoose    = require('mongoose'),
    PostsModel  = mongoose.model('Posts');

let sendError = ((code, err) => {
  if(err) return res.status(code).send(err.message);
});

//GET - Return all Posts in the DB
exports.findAll = ((req, res) => {
    PostsModel.find((err, posts) => {
      sendError(500, err);

      console.log(`GET /posts`);
      res.status(200).jsonp(posts);
    });
});

//GET - Return Post
exports.findById = ((req, res) => {
    PostsModel.findById(req.params.id, ((err, post) => {
      sendError(500, err);

      console.log(`GET /posts/${req.params.id}`);
      res.status(200).jsonp(post);
    }));
});


//POST - add new Document Post
exports.add = ((req, res) => {
  let post = new PostsModel({
    title:  req.body.title,
    subject:  req.body.subject,
    body:   req.body.body
  });

  console.log(`POST /posts/`);
  console.log(req.body);
  post.save(((err, post) => {
    sendError(500, err);

    res.status(200).jsonp(post);
  }));
});

//PUT - update a Post by Id
exports.update = ((req, res) => {
	PostsModel.findById(req.params.id, ((err, post) => {
    post.title = req.body.title;
    post.subject = req.body.subject;
		post.body = req.body.body;

		post.save(((err) => {
			sendError(500, err);
      res.status(200).jsonp(post);
		}));
	}));
});

//DELETE - Delete a Post with specified ID
exports.delete = ((req, res) => {
	PostsModel.findById(req.params.id, ((err, post) => {
		post.remove(((err) => {
			sendError(500, err);
      res.status(200);
		}));
	}));
});

@@ -174,32 +174,215 @@
 .message);%0A%7D);%0A%0A
+let sendResponse = ((res, code, data) =%3E %7B%0A  let path = %60$%7Bres.req.originalMethod%7D  $%7Bres.req.originalUrl%7D%60;%0A  console.log(%60$%7Bpath%7D    $%7Bcode%7D%60);%0A  res.status(code).jsonp(data);%0A%7D);%0A%0A
 //GET - Return a
@@ -511,63 +511,31 @@
     
-console.log(%60GET /posts%60);%0A      res.status(200).jsonp(
+sendResponse(res, 200, 
 post
@@ -697,16 +697,19 @@
 ;%0A%0A     
+ //
  console
@@ -751,38 +751,39 @@
 ;%0A      
-res.status(200).jsonp(
+sendResponse(res, 200, 
 post);%0A 
@@ -987,38 +987,10 @@
 %0A%0A  
-console.log(%60POST /posts/%60);%0A 
+//
  con
@@ -1069,38 +1069,39 @@
 );%0A%0A    
-res.status(200).jsonp(
+sendResponse(res, 200, 
 post);%0A 
@@ -1379,36 +1379,38 @@
 r);%0A
+%0A
       
-res.status(200).jsonp(
+sendResponse(res, 200, 
 post
@@ -1519,32 +1519,41 @@
 tsModel.findById
+AndRemove
 (req.params.id, 
@@ -1576,83 +1576,191 @@
 %7B%0A%09%09
-post.remove(((err) =%3E %7B%0A%09%09%09sendError(500, err);%0A      res.status(200);%0A%09%09%7D)
+sendError(500, err);%0A%0A    if (null == post) %7B%0A      return sendResponse(res, 404, post);%0A      console.log(%60No exist  /posts/$%7Breq.params.id%7D%60);%0A    %7D%0A%0A    sendResponse(res, 200, post
 );%0A%09

Add log to request and responses