{"size": 1231, "ext": "js", "max_stars_repo_path": "backend/routes/usuario.route.js", "max_stars_repo_name": "santiagovasquez1/Wired_In", "max_stars_repo_stars_event_min_datetime": "2021-09-12T23:33:39.000Z", "max_stars_repo_stars_event_max_datetime": "2021-09-12T23:33:39.000Z", "max_issues_repo_path": "backend/routes/usuario.route.js", "max_issues_repo_name": "santiagovasquez1/Wired_In", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "backend/routes/usuario.route.js", "max_forks_repo_name": "santiagovasquez1/Wired_In", "max_forks_repo_forks_event_min_datetime": "2021-09-14T01:08:21.000Z", "max_forks_repo_forks_event_max_datetime": "2021-09-14T01:08:21.000Z"}
{"max_stars_count": 1, "max_issues_count": null, "max_forks_count": 1, "avg_line_length": 27.9772727273, "max_line_length": 74, "alphanum_fraction": 0.6474411048}
/*
    Ruta: /api/usuarios
*/

const { Router } = require('express');
const {
    getUsuarios,
    crearUsuario,
    actualizarUsurario,
    borrarUsuario,
    getUsersByRol,
} = require('../controllers/usuario.controller');
const { check } = require('express-validator');
const { validarCampos } = require('../middlewares/validarCampos');
const { validarUsuario } = require('../middlewares/validarUsuario');

const router = Router();

router.get('/', validarUsuario, getUsuarios);

router.post('/', [validarUsuario,
        check('nombre', 'El nombre es obligatorio').not().isEmpty(),
        check('password', 'El password es obligatorio').not().isEmpty(),
        check('email', 'El email no tiene el formato correcto').isEmail(),
        validarCampos
    ],
    crearUsuario);

router.put(
    '/:id', [
        validarUsuario,
        check('nombre', 'El nombre es obligatorio').not().isEmpty(),
        check('email', 'El email no tiene el formato correcto').isEmail(),
        check('rol', 'El rol es obligatorio').not().isEmpty(),
        validarCampos,
    ],
    actualizarUsurario
);

router.delete('/:id', [validarUsuario], borrarUsuario);

router.get('/:rol', validarUsuario, getUsersByRol);

module.exports = router;