2020-11-16 12:47:46 -06:00
|
|
|
const express = require('express');
|
2020-11-22 18:27:54 -06:00
|
|
|
const multer = require('multer');
|
2020-11-16 12:47:46 -06:00
|
|
|
const app = express();
|
2020-11-22 18:27:54 -06:00
|
|
|
const upload = multer({ dest: 'server/uploads' });
|
2021-01-05 15:34:00 -06:00
|
|
|
const { verificaToken } = require('../middleware/autentificacion');
|
2021-05-13 14:06:07 -05:00
|
|
|
const { eliminarArchivo } = require('../helper/helper');
|
2020-11-16 12:47:46 -06:00
|
|
|
const route = '/servicio';
|
2021-05-05 18:49:23 -05:00
|
|
|
const controllerPath = '../controller/Servicio';
|
|
|
|
|
const nuevo = require(`${controllerPath}/nuevo`);
|
|
|
|
|
const serviciosAdmin = require(`${controllerPath}/serviciosAdmin`);
|
|
|
|
|
const serviciosResponsable = require(`${controllerPath}/serviciosResponsable`);
|
|
|
|
|
const admin = require(`${controllerPath}/admin`);
|
|
|
|
|
const alumno = require(`${controllerPath}/alumno`);
|
|
|
|
|
const cancelar = require(`${controllerPath}/cancelar`);
|
|
|
|
|
const registro = require(`${controllerPath}/registro`);
|
|
|
|
|
const registroValidado = require(`${controllerPath}/registroValidado`);
|
|
|
|
|
const cartaAceptacion = require(`${controllerPath}/cartaAceptacion`);
|
|
|
|
|
const cartaTermino = require(`${controllerPath}/cartaTermino`);
|
|
|
|
|
const informeGlobal = require(`${controllerPath}/informeGlobal`);
|
|
|
|
|
const liberacion = require(`${controllerPath}/liberacion`);
|
|
|
|
|
const rechazarAceptacion = require(`${controllerPath}/rechazarAceptacion`);
|
|
|
|
|
const rechazarTermino = require(`${controllerPath}/rechazarTermino`);
|
|
|
|
|
const rechazarInforme = require(`${controllerPath}/rechazarInforme`);
|
|
|
|
|
const update = require(`${controllerPath}/update`);
|
|
|
|
|
const reporte = require(`${controllerPath}/reporte`);
|
|
|
|
|
const gustavoBazPrada = require(`${controllerPath}/gustavoBazPrada`);
|
2021-01-05 23:59:05 -06:00
|
|
|
|
2021-05-13 14:06:07 -05:00
|
|
|
// POST
|
2021-01-05 18:27:38 -06:00
|
|
|
app.post(
|
|
|
|
|
`${route}/nuevo`,
|
|
|
|
|
// verificaToken,
|
|
|
|
|
upload.single('cartaAceptacion'),
|
|
|
|
|
(req, res) => {
|
|
|
|
|
return nuevo(JSON.parse(req.body.alumno), req.file.filename)
|
|
|
|
|
.then((data) => {
|
|
|
|
|
res.status(201).json(data);
|
|
|
|
|
})
|
|
|
|
|
.catch((err) => {
|
2021-01-05 23:59:05 -06:00
|
|
|
if (req.file.filename) eliminarArchivo(req.file.filename);
|
2021-01-05 18:27:38 -06:00
|
|
|
res.status(400).json({ message: err.message });
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
);
|
2020-11-16 12:47:46 -06:00
|
|
|
|
2021-05-13 14:06:07 -05:00
|
|
|
// GET
|
2021-01-05 18:27:38 -06:00
|
|
|
app.get(`${route}/admin`, verificaToken, (req, res) => {
|
2020-11-19 11:47:23 -06:00
|
|
|
return admin(req.query)
|
|
|
|
|
.then((data) => {
|
|
|
|
|
res.status(200).json(data);
|
|
|
|
|
})
|
|
|
|
|
.catch((err) => {
|
|
|
|
|
res.status(400).json({ message: err.message });
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
2021-01-05 18:27:38 -06:00
|
|
|
app.get(`${route}/alumno`, verificaToken, (req, res) => {
|
2020-11-19 11:47:23 -06:00
|
|
|
return alumno(req.query)
|
2020-11-17 14:33:33 -06:00
|
|
|
.then((data) => {
|
|
|
|
|
res.status(200).json(data);
|
|
|
|
|
})
|
|
|
|
|
.catch((err) => {
|
|
|
|
|
res.status(400).json({ message: err.message });
|
|
|
|
|
});
|
|
|
|
|
});
|
2020-11-17 13:49:31 -06:00
|
|
|
|
2021-05-13 14:06:07 -05:00
|
|
|
app.get(`${route}/gustavo_baz_prada`, verificaToken, (req, res) => {
|
|
|
|
|
return gustavoBazPrada(req.query)
|
2021-04-05 15:24:18 -05:00
|
|
|
.then((data) => {
|
2021-05-12 19:08:28 -05:00
|
|
|
res.download(data);
|
2021-04-05 15:24:18 -05:00
|
|
|
})
|
|
|
|
|
.catch((err) => {
|
|
|
|
|
res.status(400).json({ message: err.message });
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
2021-05-13 14:06:07 -05:00
|
|
|
app.get(`${route}/reporte`, verificaToken, (req, res) => {
|
|
|
|
|
return reporte(req.query)
|
2021-04-05 15:24:18 -05:00
|
|
|
.then((data) => {
|
2021-05-12 19:08:28 -05:00
|
|
|
res.download(data);
|
2021-04-05 15:24:18 -05:00
|
|
|
})
|
|
|
|
|
.catch((err) => {
|
|
|
|
|
res.status(400).json({ message: err.message });
|
|
|
|
|
});
|
|
|
|
|
});
|
2021-03-01 11:13:22 -06:00
|
|
|
|
2021-05-13 14:06:07 -05:00
|
|
|
app.get(`${route}/servicios_admin`, verificaToken, (req, res) => {
|
|
|
|
|
return serviciosAdmin(req.query)
|
2020-11-22 19:27:29 -06:00
|
|
|
.then((data) => {
|
|
|
|
|
res.status(200).json(data);
|
|
|
|
|
})
|
|
|
|
|
.catch((err) => {
|
|
|
|
|
res.status(400).json({ message: err.message });
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
2021-05-13 14:06:07 -05:00
|
|
|
app.get(`${route}/servicios_responsable`, verificaToken, (req, res) => {
|
|
|
|
|
return serviciosResponsable(req.query)
|
2020-11-22 20:36:55 -06:00
|
|
|
.then((data) => {
|
|
|
|
|
res.status(200).json(data);
|
|
|
|
|
})
|
|
|
|
|
.catch((err) => {
|
|
|
|
|
res.status(400).json({ message: err.message });
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
2021-05-13 14:06:07 -05:00
|
|
|
// PUT
|
|
|
|
|
app.put(`${route}/cancelar`, verificaToken, (req, res) => {
|
|
|
|
|
return cancelar(req.body)
|
2020-11-22 21:05:50 -06:00
|
|
|
.then((data) => {
|
|
|
|
|
res.status(200).json(data);
|
|
|
|
|
})
|
|
|
|
|
.catch((err) => {
|
|
|
|
|
res.status(400).json({ message: err.message });
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
2020-12-10 10:00:35 -06:00
|
|
|
app.put(
|
|
|
|
|
`${route}/carta_aceptacion`,
|
2021-01-05 18:27:38 -06:00
|
|
|
// verificaToken,
|
2020-12-10 10:00:35 -06:00
|
|
|
upload.single('cartaAceptacion'),
|
|
|
|
|
(req, res) => {
|
|
|
|
|
return cartaAceptacion(JSON.parse(req.body.data), req.file.filename)
|
|
|
|
|
.then((data) => {
|
|
|
|
|
res.status(200).json(data);
|
|
|
|
|
})
|
|
|
|
|
.catch((err) => {
|
2021-01-05 23:59:05 -06:00
|
|
|
if (req.file.filename) eliminarArchivo(req.file.filename);
|
2020-12-10 10:00:35 -06:00
|
|
|
res.status(400).json({ message: err.message });
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
);
|
2020-11-29 17:48:06 -06:00
|
|
|
|
2021-01-05 18:27:38 -06:00
|
|
|
app.put(
|
|
|
|
|
`${route}/carta_termino`,
|
|
|
|
|
// verificaToken,
|
|
|
|
|
upload.single('cartaTermino'),
|
|
|
|
|
(req, res) => {
|
|
|
|
|
return cartaTermino(JSON.parse(req.body.data), req.file.filename)
|
|
|
|
|
.then((data) => {
|
|
|
|
|
res.status(200).json(data);
|
|
|
|
|
})
|
|
|
|
|
.catch((err) => {
|
2021-01-05 23:59:05 -06:00
|
|
|
if (req.file.filename) eliminarArchivo(req.file.filename);
|
2021-01-05 18:27:38 -06:00
|
|
|
res.status(400).json({ message: err.message });
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
);
|
2020-11-23 00:52:38 -06:00
|
|
|
|
|
|
|
|
app.put(
|
|
|
|
|
`${route}/informe_global`,
|
2021-01-05 18:27:38 -06:00
|
|
|
// verificaToken,
|
2020-11-23 00:52:38 -06:00
|
|
|
upload.single('informeGlobal'),
|
|
|
|
|
(req, res) => {
|
|
|
|
|
return informeGlobal(JSON.parse(req.body.data), req.file.filename)
|
|
|
|
|
.then((data) => {
|
|
|
|
|
res.status(200).json(data);
|
|
|
|
|
})
|
|
|
|
|
.catch((err) => {
|
2021-01-05 23:59:05 -06:00
|
|
|
if (req.file.filename) eliminarArchivo(req.file.filename);
|
2020-11-23 00:52:38 -06:00
|
|
|
res.status(400).json({ message: err.message });
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
);
|
|
|
|
|
|
2021-01-05 18:27:38 -06:00
|
|
|
app.put(`${route}/liberacion`, verificaToken, (req, res) => {
|
2020-11-23 12:43:33 -06:00
|
|
|
return liberacion(req.body)
|
|
|
|
|
.then((data) => {
|
|
|
|
|
res.status(200).json(data);
|
|
|
|
|
})
|
|
|
|
|
.catch((err) => {
|
|
|
|
|
res.status(400).json({ message: err.message });
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
2021-05-13 14:06:07 -05:00
|
|
|
app.put(`${route}/registro`, verificaToken, (req, res) => {
|
|
|
|
|
return registro(req.body)
|
2020-11-27 19:16:07 -06:00
|
|
|
.then((data) => {
|
|
|
|
|
res.status(200).json(data);
|
|
|
|
|
})
|
|
|
|
|
.catch((err) => {
|
|
|
|
|
res.status(400).json({ message: err.message });
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
2021-05-13 14:06:07 -05:00
|
|
|
app.put(`${route}/registro_validado`, verificaToken, (req, res) => {
|
|
|
|
|
return registroValidado(req.body)
|
|
|
|
|
.then((data) => {
|
|
|
|
|
res.status(200).json(data);
|
|
|
|
|
})
|
|
|
|
|
.catch((err) => {
|
|
|
|
|
res.status(400).json({ message: err.message });
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
app.put(`${route}/rechazar_aceptacion`, verificaToken, (req, res) => {
|
|
|
|
|
return rechazarAceptacion(req.body)
|
2020-11-27 19:16:07 -06:00
|
|
|
.then((data) => {
|
|
|
|
|
res.status(200).json(data);
|
|
|
|
|
})
|
|
|
|
|
.catch((err) => {
|
|
|
|
|
res.status(400).json({ message: err.message });
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
2021-01-05 18:27:38 -06:00
|
|
|
app.put(`${route}/rechazar_informe`, verificaToken, (req, res) => {
|
2020-11-27 19:16:07 -06:00
|
|
|
return rechazarInforme(req.body)
|
|
|
|
|
.then((data) => {
|
|
|
|
|
res.status(200).json(data);
|
|
|
|
|
})
|
|
|
|
|
.catch((err) => {
|
|
|
|
|
res.status(400).json({ message: err.message });
|
2021-05-13 14:06:07 -05:00
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
app.put(`${route}/rechazar_termino`, verificaToken, (req, res) => {
|
|
|
|
|
return rechazarTermino(req.body)
|
|
|
|
|
.then((data) => {
|
|
|
|
|
res.status(200).json(data);
|
|
|
|
|
})
|
|
|
|
|
.catch((err) => {
|
|
|
|
|
res.status(400).json({ message: err.message });
|
2020-11-27 19:16:07 -06:00
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
2021-01-05 23:59:05 -06:00
|
|
|
app.put(
|
|
|
|
|
`${route}/update`,
|
|
|
|
|
// verificaToken ,
|
|
|
|
|
upload.fields([
|
|
|
|
|
{ name: 'cartaAceptacion', maxCount: 1 },
|
|
|
|
|
{ name: 'cartaTermino', maxCount: 1 },
|
|
|
|
|
{ name: 'informeGlobal', maxCount: 1 },
|
|
|
|
|
]),
|
|
|
|
|
(req, res) => {
|
|
|
|
|
return update(JSON.parse(req.body.data), req.files)
|
|
|
|
|
.then((data) => {
|
|
|
|
|
res.status(200).json(data);
|
|
|
|
|
})
|
|
|
|
|
.catch((err) => {
|
2021-01-06 17:45:16 -06:00
|
|
|
try {
|
|
|
|
|
if (req.files['cartaAceptacion'][0].filename)
|
|
|
|
|
eliminarArchivo(req.files['cartaAceptacion'][0].filename);
|
|
|
|
|
} catch (err) {}
|
|
|
|
|
try {
|
|
|
|
|
if (req.files['cartaTermino'][0].filename)
|
|
|
|
|
eliminarArchivo(req.files['cartaTermino'][0].filename);
|
|
|
|
|
} catch (err) {}
|
|
|
|
|
try {
|
|
|
|
|
if (req.files['informeGlobal'][0].filename)
|
|
|
|
|
eliminarArchivo(req.files['informeGlobal'][0].filename);
|
|
|
|
|
} catch (err) {}
|
2021-01-05 23:59:05 -06:00
|
|
|
res.status(400).json({ message: err.message });
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
);
|
|
|
|
|
|
2020-11-16 12:47:46 -06:00
|
|
|
module.exports = app;
|