
const express = require('express');
const Claim_requestsService = require('../services/claim_requests');
const wrapAsync = require('../helpers').wrapAsync;
const { checkPermissions } = require('../middlewares/check-permissions');

const router = express.Router();

router.get('/', checkPermissions('READ_CLAIM_REQUESTS'), wrapAsync(async (req, res) => {
    const payload = await Claim_requestsService.findAll(req.query, req.currentUser);
    res.status(200).send(payload);
}));

router.get('/:id', checkPermissions('READ_CLAIM_REQUESTS'), wrapAsync(async (req, res) => {
    const payload = await Claim_requestsService.findBy(req.params.id);
    res.status(200).send(payload);
}));

router.post('/', wrapAsync(async (req, res) => {
    const payload = await Claim_requestsService.create(req.body.data, req.currentUser);
    res.status(200).send(payload);
}));

router.put('/:id', checkPermissions('UPDATE_CLAIM_REQUESTS'), wrapAsync(async (req, res) => {
    const payload = await Claim_requestsService.update(req.params.id, req.body.data, req.currentUser);
    res.status(200).send(payload);
}));

module.exports = router;
