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

router.post("/create", authorize(), create);
router.post("/", authorize(), getAll);
router.get("/option", authorize(), option);
router.get("/count", authorize(), count);
router.put("/:id", authorize(), update);
router.put("/enabled/:id", authorize(), enabled);
router.delete("/:id", authorize(), _delete);

module.exports = router;

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

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

function option(req, res, next) {
  expeditionService
    .option(req.query)
    .then((result) => res.json(result))
    .catch(next);
}

function count(req, res, next) {
  expeditionService
    .count(req.query)
    .then((result) => res.json(result))
    .catch(next);
}

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

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

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