2021-04-26 19:19:16 -05:00
|
|
|
const express = require('express');
|
|
|
|
|
const app = express();
|
|
|
|
|
const { verificaToken } = require('../middleware/autentificacion');
|
|
|
|
|
const route = '/operador';
|
2021-05-03 23:38:03 -05:00
|
|
|
const controllerPath = '../controller/Operador';
|
|
|
|
|
const crear = require(`${controllerPath}/crear`);
|
2021-05-26 15:47:24 -05:00
|
|
|
const login = require(`${controllerPath}/login`);
|
2021-05-04 00:32:04 -05:00
|
|
|
const operadores = require(`${controllerPath}/operadores`);
|
2021-05-26 15:47:24 -05:00
|
|
|
const update = require(`${controllerPath}/update`);
|
2021-04-26 19:19:16 -05:00
|
|
|
|
2021-05-26 15:47:24 -05:00
|
|
|
// POST
|
2021-04-26 19:19:16 -05:00
|
|
|
app.post(`${route}/login`, (req, res) => {
|
|
|
|
|
return login(req.body)
|
|
|
|
|
.then((data) => {
|
|
|
|
|
res.status(200).json(data);
|
|
|
|
|
})
|
|
|
|
|
.catch((err) => {
|
|
|
|
|
res.status(400).json({ message: err.message });
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
2021-04-27 23:32:40 -05:00
|
|
|
app.post(`${route}/crear`, (req, res) => {
|
|
|
|
|
return crear(req.body)
|
|
|
|
|
.then((data) => {
|
|
|
|
|
res.status(201).json(data);
|
|
|
|
|
})
|
|
|
|
|
.catch((err) => {
|
|
|
|
|
res.status(400).json({ message: err.message });
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
2021-05-26 15:47:24 -05:00
|
|
|
// PUT
|
|
|
|
|
app.put(`${route}/update`, (req, res) => {
|
|
|
|
|
return update(req.body)
|
|
|
|
|
.then((data) => {
|
|
|
|
|
res.status(201).json(data);
|
|
|
|
|
})
|
|
|
|
|
.catch((err) => {
|
|
|
|
|
res.status(400).json({ message: err.message });
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
// GET
|
2021-05-04 00:32:04 -05:00
|
|
|
app.get(`${route}/operadores`, (req, res) => {
|
|
|
|
|
return operadores(req.query)
|
|
|
|
|
.then((data) => {
|
|
|
|
|
res.status(201).json(data);
|
|
|
|
|
})
|
|
|
|
|
.catch((err) => {
|
|
|
|
|
res.status(400).json({ message: err.message });
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
2021-04-26 19:19:16 -05:00
|
|
|
module.exports = app;
|