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

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

module.exports = router;

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

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

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

function show(req, res, next) {
  jobPostingService
    .show()
    .then((result) => res.json(result))
    .catch(next);
}

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

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

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

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

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

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