const express = require("express");
const router = express.Router();
const authorize = require("../../../../middlewares/authorize-sapps");
const workActivityPlanService = require("./workActivityPlan.service");

router.post("/create", authorize(), create);
router.post("/create-workflow", authorize(), createWorkflow);
router.post("/", authorize(), getAll);
router.get("/:id", authorize(), getById);
router.put("/:id", authorize(), update);
router.delete("/:id", authorize(), _delete);

module.exports = router;

function create(req, res, next) {
  workActivityPlanService
    .create(req.body)
    .then((result) => res.json(result))
    .catch(next);
}

function createWorkflow(req, res, next) {
  workActivityPlanService
    .createWorkflow(req.body)
    .then((result) => res.json(result))
    .catch(next);
}

function getAll(req, res, next) {
  workActivityPlanService
    .getAll(req.body)
    .then((result) => res.json(result))
    .catch(next);
}

function getById(req, res, next) {
  workActivityPlanService
    .getById(req.params.id)
    .then((result) => res.json(result))
    .catch(next);
}

function update(req, res, next) {
  workActivityPlanService
    .update(req.params.id, req.body)
    .then((result) => res.json(result))
    .catch(next);
}

function _delete(req, res, next) {
  workActivityPlanService
    .delete(req.params.id)
    .then((result) => res.json(result))
    .catch(next);
}
