const express = require('express');
const router = express.Router();
const authorize = require('../../../../middlewares/authorize-sapps');
const designationVersionService = require('./designationVersion.service');

router.post('/create', authorize(), create);
router.post('/', authorize(), getAll);
router.post('/filter', authorize(), filter);
router.post('/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) {
    designationVersionService.create(req.body)
        .then(result => res.json(result))
        .catch(next);
}

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

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

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

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

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

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

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


