const express = require('express');
const router = express.Router();
const accessoryService = require('./accessory.service');

router.post('/create', create);
router.get('/', getAll);
router.get('/:id', getById);
router.put('/:id', update);
router.delete('/:id', _delete);
router.post('/checkout', checkout);
router.post('/checkin/:id', checkin);

module.exports = router;

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

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

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

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

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

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

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