const express = require('express');
const router = express.Router();
const { requireAuth } = require('../middleware/auth');
const { createRequirePage } = require('../../../shared/middleware/pagePermission');
const { getPool } = require('../../shared/config/database');
const requirePage = createRequirePage(getPool);
const ctrl = require('../controllers/consumableItemController');
const { consumableUpload } = require('../middleware/upload');

router.use(requireAuth);

router.get('/', ctrl.list);
router.get('/:id', ctrl.getById);
router.post('/', requirePage('tkuser.consumables'), consumableUpload.single('photo'), ctrl.create);
router.put('/:id', requirePage('tkuser.consumables'), consumableUpload.single('photo'), ctrl.update);
router.delete('/:id', requirePage('tkuser.consumables'), ctrl.deactivate);

module.exports = router;
