{"size": 806, "ext": "js", "max_stars_repo_path": "src/routes/tasks.js", "max_stars_repo_name": "dennisvillagaray/mevn", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/routes/tasks.js", "max_issues_repo_name": "dennisvillagaray/mevn", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/routes/tasks.js", "max_forks_repo_name": "dennisvillagaray/mevn", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 20.6666666667, "max_line_length": 55, "alphanum_fraction": 0.6215880893}
const express = require('express');
const router = express.Router()

const Task = require('../models/Task');

router.get('/', async (req, res) => {
  const task = await Task.find()
  res.json(task)
})

router.get('/:id', async (req, res) => {
  const task =await Task.findById(req.params.id)
  res.json(task)
})

router.post('/', async (req, res) => {
  const task = new Task(req.body)
  await task.save()
  res.json({
    status: 'Task Saved'
  })
})

router.put('/:id', async (req, res) => {
  // const { title, description } = req.body
  await Task.findByIdAndUpdate(req.params.id, req.body)
  res.json({
    status: 'Task Updated'
  })
})

router.delete('/:id', async (req, res) => {
  await Task.findByIdAndRemove(req.params.id)
  res.json({
    status: 'Task Deleted'
  })
})

module.exports = router