{"size": 903, "ext": "js", "max_stars_repo_path": "controllers/task.js", "max_stars_repo_name": "irfanabduhu/scrum", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "controllers/task.js", "max_issues_repo_name": "irfanabduhu/scrum", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "controllers/task.js", "max_forks_repo_name": "irfanabduhu/scrum", "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": 22.575, "max_line_length": 58, "alphanum_fraction": 0.5802879291}
const Task = require("../models/task");

exports.postNewTask = (req, res) => {
  console.log("Creating a new task");
  const task_name = req.body.taskName;
  const board_id = req.session.board_id;
  Task.create({
    text: task_name,
    status: "todo",
    board_id: board_id,
  })
    .then(() => {
      console.log("created");
      res.redirect(`/board/${board_id}`);
    })
    .catch((err) => console.err(err));
};

exports.updateTask = (req, res) => {
  const task_id = +req.params.id;
  const status = req.body.status;

  Task.findByPk(task_id)
    .then((task) => {
      task.status = status;
      task.save();
    })
    .catch((err) => console.error("Update error: ", err));
};

exports.deleteTask = (req, res) => {
  const task_id = +req.params.id;

  Task.findByPk(task_id)
    .then((task) => {
      task.destroy();
    })
    .catch((err) => console.error("Delete error: ", err));
};
