{"size": 962, "ext": "js", "max_stars_repo_path": "src/controllers/Posts.controller.js", "max_stars_repo_name": "flowck/graphql-jsonplaceholder", "max_stars_repo_stars_event_min_datetime": "2019-07-16T21:57:55.000Z", "max_stars_repo_stars_event_max_datetime": "2019-07-17T08:44:23.000Z", "max_issues_repo_path": "src/controllers/Posts.controller.js", "max_issues_repo_name": "flowck/graphql-jsonplaceholder", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/controllers/Posts.controller.js", "max_forks_repo_name": "flowck/graphql-jsonplaceholder", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": 2, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 16.5862068966, "max_line_length": 59, "alphanum_fraction": 0.5925155925}
/**
 * Posts controller
*/
const fs = require("fs");
const db = require("../data.json");

/**
 * getPosts: It return a list of posts
 * 
 * @returns {array}
*/
module.exports.getPosts = () => {
  return db.posts;
}

/**
 * getSinglePost: It return a single item from the database
 * 
 * @returns {object}
*/
module.exports.getSinglePost = (id) => {
  return db.posts.find(post => post.id === id);
}

/**
 * createPost: It creates a new post
 * 
 * @returns {object}
*/
module.exports.createPost = (data) => {
  return data;
}

/**
 * updatePost: It update a single post by its id
 * 
 * @returns {object}
*/
module.exports.updatePost = (data) => {
  const post = db.posts.find(post => post.id === data.id);
  if (post) {
    return {
      ...post,
      ...data
    }
  }
  return {};
}

/**
 * removePost: It removes a single post by its id
 * 
 * @returns {boolean}
*/
module.exports.removePost = (id) => {
  // I will implement a logic later
  return true;
}