const express = require('express');
const router = express.Router();
const licenseService = require('./license.service');

router.post('/create', create);
router.get('/', getAll);
router.get('/:id', getById);
router.put('/:id', update);
router.delete('/:id', _delete);
router.post('/assign-seat', assignSeat);
router.post('/revoke-seat/:id', revokeSeat);

module.exports = router;

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

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

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

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

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

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

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