diff --git a/server/controller/CasoEspecial/nuevo.js b/server/controller/CasoEspecial/nuevo.js index 22363c4..9fa0860 100644 --- a/server/controller/CasoEspecial/nuevo.js +++ b/server/controller/CasoEspecial/nuevo.js @@ -11,6 +11,7 @@ const nuevo = async (body, file) => { const numeroCuenta = validar.validarNumeroCuenta(body.numeroCuenta); const creditos = validar.validarNumero(body.creditos); const correo = validar.validarCorreo(body.correo); + const telefono = validar.validarNumero(body.telefono, 15); const fechaInicio = validar.validarFecha(body.fechaInicio); const fechaFin = validar.validarFecha(body.fechaFin); const fechaNacimiento = validar.validarFecha(body.fechaNacimiento); @@ -20,10 +21,10 @@ const nuevo = async (body, file) => { 200 ); const institucion = body.institucion - ? validar.validarTexto(body.institucion, 'El texto institucion.', 100) + ? validar.validarTexto(body.institucion, 'El texto institucion.', 200) : ''; const dependencia = body.dependencia - ? validar.validarTexto(body.dependencia, 'El texto dependencia.', 100) + ? validar.validarTexto(body.dependencia, 'El texto dependencia.', 200) : ''; const motivo = body.motivo ? validar.validarNumero(body.motivo, 'El texto motivo.', 1) @@ -52,12 +53,7 @@ const nuevo = async (body, file) => { }) .then((res) => { carpeta = res; - return drive.uploadFile( - path, - `archivos.rar`, - 'application/x-rar', - carpeta - ); + return drive.uploadFile(path, `archivos.zip`, 'application/zip', carpeta); }) .then((res) => CasoEspecial.create({ @@ -66,6 +62,7 @@ const nuevo = async (body, file) => { idStatus, creditos, correo, + telefono, institucion, dependencia, motivo, diff --git a/server/controller/CasoEspecial/update.js b/server/controller/CasoEspecial/update.js new file mode 100644 index 0000000..c55f96a --- /dev/null +++ b/server/controller/CasoEspecial/update.js @@ -0,0 +1,55 @@ +const validar = require('../../helper/validar'); +const CasoEspecial = require('../../db/tablas/CasoEspecial'); + +const update = async (body) => { + const idCasoEspecial = validar.validarId(body.idCasoEspecial); + const dataUpdate = {}; + + return CasoEspecial.findOne({ where: { idCasoEspecial } }) + .then(async (res) => { + if (!res) throw new Error('Este Caso Especial no existe en la db.'); + if (body.correo) dataUpdate.correo = validar.validarCorreo(body.correo); + if (body.fechaInicio) + dataUpdate.fechaInicio = validar.validarFecha(body.fechaInicio); + if (body.fechaFin) + dataUpdate.fechaFin = validar.validarFecha(body.fechaFin); + if (body.fechaNacimiento) + dataUpdate.fechaNacimiento = validar.validarFecha(body.fechaNacimiento); + if (body.direccion) + dataUpdate.direccion = validar.validarAlfanumerico( + body.direccion, + 'La dirección', + 200 + ); + if (body.telefono) + dataUpdate.telefono = validar.validarNumero(body.telefono, 15); + if (body.institucion) + dataUpdate.institucion = validar.validarTexto( + body.institucion, + 'El texto institucion.', + 200 + ); + if (body.dependencia) + dataUpdate.dependencia = validar.validarTexto( + body.dependencia, + 'El texto dependencia.', + 200 + ); + if (body.motivo) + dataUpdate.motivo = validar.validarNumero( + body.motivo, + 'El texto motivo.', + 1 + ); + if (validar.isObjectEmpty(dataUpdate)) + throw new Error( + 'No se envio nada para actualizar este Caso Especial.' + ); + return CasoEspecial.update(dataUpdate, { where: { idCasoEspecial } }); + }) + .then((res) => ({ + message: 'Se guardo correctamente los cambios de este servicio.', + })); +}; + +module.exports = update; diff --git a/server/controller/CuestionarioAlumno/get.js b/server/controller/CuestionarioAlumno/get.js index 0a78a01..fa6ee41 100644 --- a/server/controller/CuestionarioAlumno/get.js +++ b/server/controller/CuestionarioAlumno/get.js @@ -67,7 +67,7 @@ const get = async (body) => { try { fs.unlinkSync(path); } catch (err) { - throw new Error(err); + console.log(err); } fs.appendFile(path, convertArrayToCSV(data), (err) => { if (err) throw new Error(err); diff --git a/server/controller/CuestionarioPrograma/get.js b/server/controller/CuestionarioPrograma/get.js index d5deeb4..797bf5a 100644 --- a/server/controller/CuestionarioPrograma/get.js +++ b/server/controller/CuestionarioPrograma/get.js @@ -43,7 +43,7 @@ const get = async (body) => { try { fs.unlinkSync(path); } catch (err) { - throw new Error(err); + console.log(err); } fs.appendFile(path, convertArrayToCSV(data), (err) => { if (err) throw new Error(err); diff --git a/server/controller/Servicio/liberacion.js b/server/controller/Servicio/liberacion.js index 11a2780..321cbe6 100644 --- a/server/controller/Servicio/liberacion.js +++ b/server/controller/Servicio/liberacion.js @@ -1,3 +1,4 @@ +const moment = require('moment'); const validar = require('../../helper/validar'); const gmail = require('../../helper/gmail'); const correos = require('../../helper/correos'); @@ -48,7 +49,11 @@ const liberacion = async (body) => { throw new Error('Id status no valido.'); } }) - .then((res) => Servicio.update(update, { where: { idServicio } })) + .then((res) => + Servicio.update(update, { + where: { idServicio, fechaLiberacion: moment() }, + }) + ) .then((res) => ({ message: 'Se cambio de estatus correctamente y se envio un correo al alumno informandole de su liberación.', diff --git a/server/controller/Servicio/reporte.js b/server/controller/Servicio/reporte.js new file mode 100644 index 0000000..f833b41 --- /dev/null +++ b/server/controller/Servicio/reporte.js @@ -0,0 +1,50 @@ +const fs = require('fs'); +const { convertArrayToCSV } = require('convert-array-to-csv'); +const { Op } = require('sequelize'); +const validar = require('../../helper/validar'); +const Servicio = require('../../db/tablas/Servicio'); +const Programa = require('../../db/tablas/Programa'); +const Usuario = require('../../db/tablas/Usuario'); +const Carrera = require('../../db/tablas/Carrera'); + +const get = async (body) => { + const inicio = validar.validarFecha(body.inicio); + const fin = validar.validarFecha(body.fin); + const path = `csv/reporte.csv`; + const data = []; + + return Servicio.findAll({ + where: { + fechaInicio: { [Op.gte]: inicio }, + fechaInicio: { [Op.lte]: fin }, + }, + include: [{ model: Programa }, { model: Usuario }, { model: Carrera }], + }).then((res) => { + for (let i = 0; i < res.length; i++) + data.push({ + numeroCuenta: res[i].Usuario.Usuario, + nombre: res[i].Usuario.nombre, + licenciatura: res[i].Carrera.carrera, + correo: res[i].correo, + fehcaInicio: res[i].fechaInicio, + fechaFin: res[i].fechaFin, + institucion: res[i].Programa.institucion, + dependencia: res[i].Programa.dependencia, + programa: res[i].Programa.programa, + clave: res[i].Programa.clavePrograma, + }); + try { + fs.unlinkSync(path); + } catch (err) { + console.log(err); + } + fs.appendFile(path, convertArrayToCSV(data), (err) => { + if (err) throw new Error(err); + }); + return { + message: `Se creo/actualizo correctamente el csv del reporte de servicios sociales.`, + }; + }); +}; + +module.exports = get; diff --git a/server/controller/Servicio/update.js b/server/controller/Servicio/update.js index 53357b2..5d96c7c 100644 --- a/server/controller/Servicio/update.js +++ b/server/controller/Servicio/update.js @@ -58,7 +58,7 @@ const update = async (body, files) => { return Servicio.update(dataUpdate, { where: { idServicio } }); }) .then((res) => ({ - message: 'Se guadro correctamente los cambios de este servicio.', + message: 'Se guardo correctamente los cambios de este servicio.', })); }; diff --git a/server/db/tablas/CasoEspecial.js b/server/db/tablas/CasoEspecial.js index 8ea8cb2..4a77331 100644 --- a/server/db/tablas/CasoEspecial.js +++ b/server/db/tablas/CasoEspecial.js @@ -22,13 +22,17 @@ CasoEspecial.init( type: DataTypes.STRING(60), allowNull: false, }, + telefono: { + type: DataTypes.STRING(15), + allowNull: false, + }, institucion: { - type: DataTypes.STRING(100), + type: DataTypes.STRING(200), allowNull: true, defaultValue: null, }, dependencia: { - type: DataTypes.STRING(100), + type: DataTypes.STRING(200), allowNull: true, defaultValue: null, }, diff --git a/server/db/tablas/Servicio.js b/server/db/tablas/Servicio.js index b9037db..8b22b5f 100644 --- a/server/db/tablas/Servicio.js +++ b/server/db/tablas/Servicio.js @@ -44,6 +44,11 @@ Servicio.init( allowNull: true, // eliminar defaultValue: null, }, + fechaLiberacion: { + type: DataTypes.DATE, + allowNull: true, + defaultValue: null, + }, fechaNacimiento: { type: DataTypes.DATE, allowNull: true, diff --git a/server/helper/diario.js b/server/helper/diario.js index fec23cd..a9c27e6 100644 --- a/server/helper/diario.js +++ b/server/helper/diario.js @@ -22,6 +22,8 @@ const diario = async () => { if (fechaFin.year() > now.year()) fechaFinDate += 365 * (fechaFin.year() - now.year()); + if (fechaFin.year() < now.year()) + fechaFinDate -= 365 * (now.year() - fechaFin.year()); if (fechaFinDate - now.dayOfYear() === 7) { let correoAlumno = correos.avisoTerminoAlumno( servicios[i].Usuario.nombre diff --git a/server/routes/CasoEspecial.js b/server/routes/CasoEspecial.js index 7104c31..9ff0197 100644 --- a/server/routes/CasoEspecial.js +++ b/server/routes/CasoEspecial.js @@ -9,6 +9,7 @@ const nuevo = require('../controller/CasoEspecial/nuevo'); const serviciosEspeciales = require('../controller/CasoEspecial/serviciosEspeciales'); const casoEspecial = require('../controller/CasoEspecial/casoEspecial'); const liberacion = require('../controller/CasoEspecial/liberacion'); +const update = require('../controller/CasoEspecial/update'); const eliminarArchivo = (filename) => { fs.unlinkSync(`./server/uploads/${filename}`); @@ -72,4 +73,18 @@ app.put( } ); +app.put( + `${route}/update`, + // verificaToken, + (req, res) => { + return update(req.body) + .then((data) => { + res.status(200).json(data); + }) + .catch((err) => { + res.status(400).json({ message: err.message }); + }); + } +); + module.exports = app; diff --git a/server/routes/Servicio.js b/server/routes/Servicio.js index 7c07196..c61f1bc 100644 --- a/server/routes/Servicio.js +++ b/server/routes/Servicio.js @@ -21,6 +21,7 @@ const rechazarAceptacion = require('../controller/Servicio/rechazarAceptacion'); const rechazarTermino = require('../controller/Servicio/rechazarTermino'); const rechazarInforme = require('../controller/Servicio/rechazarInforme'); const update = require('../controller/Servicio/update'); +const reporte = require('../controller/Servicio/reporte'); const eliminarArchivo = (filename) => { fs.unlinkSync(`./server/uploads/${filename}`); @@ -82,6 +83,20 @@ app.get(`${route}/alumno`, verificaToken, (req, res) => { }); }); +app.get( + `${route}/reporte`, + // verificaToken, + (req, res) => { + return reporte(req.query) + .then((data) => { + res.status(200).json(data); + }) + .catch((err) => { + res.status(400).json({ message: err.message }); + }); + } +); + app.put(`${route}/cancelar`, verificaToken, (req, res) => { return cancelar(req.body) .then((data) => { diff --git a/server/routes/index.js b/server/routes/index.js index 2c5581b..69195f8 100644 --- a/server/routes/index.js +++ b/server/routes/index.js @@ -4,7 +4,7 @@ const app = express(); app.use(require('./Status')); app.use(require('./Usuario')); app.use(require('./Servicio')); -// app.use(require('./CasoEspecial')); +app.use(require('./CasoEspecial')); app.use(require('./Programa')); app.use(require('./CuestionarioAlumno')); app.use(require('./CuestionarioPrograma'));