const express = require('express');
const router = express.Router();
const multer = require('multer');
const authorize = require('../../../../middlewares/authorize-sapps');
const budgetingService = require('./budgeting.service');

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

module.exports = router;

/**
 * Create a new budgeting
 */
function create(req, res, next) {
    budgetingService.create(req.body)
        .then(result => res.json(result))
        .catch(next);
}

/**
 * Get a list of all budgetings
 */
function getAll(req, res, next) {
    budgetingService.getAll(req.body)
        .then(result => res.json(result))
        .catch(next);
}

/**
 * Get an array of budgeting objects to be used as options in a select box
 */
function option(req, res, next) {
    budgetingService.option(req.body)
        .then(result => res.json(result))
        .catch(next);
}

/**
 * Count the number of budgetings matching a query
 */
function count(req, res, next) {
    budgetingService.count(req.query)
        .then(result => res.json(result))
        .catch(next);
}

/**
 * Update an existing budgeting
 */
function update(req, res, next) {
    budgetingService.update(req.params.id, req.body)
        .then(result => res.json(result))
        .catch(next);
}

/**
 * Delete a budgeting
 */
function _delete(req, res, next) {
    budgetingService.delete(req.params.id)
        .then(result => res.json(result))
        .catch(next);
}

