diff --git a/server/controller/Programa/cargaMasiva.js b/server/controller/Programa/cargaMasiva.js index f87a0fa..2260380 100644 --- a/server/controller/Programa/cargaMasiva.js +++ b/server/controller/Programa/cargaMasiva.js @@ -40,8 +40,8 @@ const cargaMasiva = async (file) => { } const acatlan = programas[i].clave.substr(4, 7) === '-12/20-'; const activo = Number(programas[i].clave.substr(0, 4)) === today.year(); - const usuario = await Usuario.findOne({ - where: { usuario: programas[i].correo }, + const responsable = await Usuario.findOne({ + where: { usuario: programas[i].correo, idTipoUsuario: 2 }, }).then(async (res) => { if (!res) { const password = encriptar.generarPassword(); @@ -58,14 +58,17 @@ const cargaMasiva = async (file) => { nombre: programas[i].nombre, activo: true, idTipoUsuario: 2, - }).then((res) => { - mensaje += `Se creo el responsable con id ${res.idUsuario} y correo ${res.usuario}\n`; - return res; - }); + }) + .then((res) => { + mensaje += `Se creo el responsable con id ${res.idUsuario} y correo ${res.usuario}\n`; + return res; + }) + .catch((err) => { + mensaje += err; + }); } return res; }); - if (!acatlan) { await Programa.findOne({ where: { clavePrograma: programas[i].clave }, @@ -79,7 +82,9 @@ const cargaMasiva = async (file) => { programa: programas[i].programa, clavePrograma: programas[i].clave, activo, - idUsuario: usuario.idUsuario, + idUsuario: responsable.idUsuario, + }).catch((err) => { + mensaje += err; }); } mensaje += `El programa ${res.clavePrograma} ya ${ @@ -93,39 +98,43 @@ const cargaMasiva = async (file) => { }) .then((res) => { if (res) - mensaje += `Se asigno el programa ${res.clavePrograma} con id ${res.idPrograma} al usuario con correo ${usuario.idUsuario} y correo ${usuario.usuario}\n`; + mensaje += `Se asigno el programa ${res.clavePrograma} con id ${res.idPrograma} al usuario con correo ${responsable.idUsuario} y correo ${responsable.usuario}\n`; }); } else { await Programa.findOne({ where: { clavePrograma: programas[i].clave, - idUsuario: usuario.idUsuario, + idUsuario: responsable.idUsuario, }, }) .then((res) => { if (!res) { return Programa.create({ - institucion: programas[i].institucion, - dependencia: programas[i].dependencia, + institucion: 'UNAM', + dependencia: 'FES ACATLAN', programa: programas[i].programa, clavePrograma: programas[i].clave, activo, acatlan, - idUsuario: usuario.idUsuario, + idUsuario: responsable.idUsuario, + }).catch((err) => { + mensaje += err; }); } - mensaje += `El programa ${res.clavePrograma} ya pertenece al responsable con id ${usuario.idUsuario} y correo ${usuario.usuario}\n`; + mensaje += `El programa ${res.clavePrograma} ya pertenece al responsable con id ${responsable.idUsuario} y correo ${responsable.usuario}\n`; return false; }) .then((res) => { if (res) - mensaje += `Se asigno el programa ${res.clavePrograma} con id ${res.idPrograma} al usuario con correo ${usuario.idUsuario} y correo ${usuario.usuario}\n`; + mensaje += `Se asigno el programa ${res.clavePrograma} con id ${res.idPrograma} al usuario con correo ${responsable.idUsuario} y correo ${responsable.usuario}\n`; }); } mensaje += '\n'; } await gmail('Reporte carga masiva', 'lemuel@acatlan.unam.mx', mensaje); await gmail('Reporte carga masiva', 'dscad@acatlan.unam.mx', mensaje); + await gmail('Reporte carga masiva', 'tramites.ss@acatlan.unam.mx', mensaje); + fs.unlinkSync(path); }); return { diff --git a/server/controller/Servicio/rechazarAceptacion.js b/server/controller/Servicio/rechazarAceptacion.js index 363852e..4790dd2 100644 --- a/server/controller/Servicio/rechazarAceptacion.js +++ b/server/controller/Servicio/rechazarAceptacion.js @@ -57,7 +57,7 @@ const cancelar = async (body) => { ) .then((res) => Servicio.update( - { idStatus: 7, cartaAceptacion: null }, + { idStatus: 7, cartaAceptacion: '' }, { where: { idServicio } } ) ) diff --git a/server/controller/Servicio/rechazarInforme.js b/server/controller/Servicio/rechazarInforme.js index 470fa3f..a88b773 100644 --- a/server/controller/Servicio/rechazarInforme.js +++ b/server/controller/Servicio/rechazarInforme.js @@ -58,7 +58,7 @@ const cancelar = async (body) => { ) .then((res) => Servicio.update( - { idStatus: 9, informeGlobal: null }, + { idStatus: 9, informeGlobal: '' }, { where: { idServicio } } ) ) diff --git a/server/controller/Servicio/rechazarTermino.js b/server/controller/Servicio/rechazarTermino.js index 43e37a4..d240157 100644 --- a/server/controller/Servicio/rechazarTermino.js +++ b/server/controller/Servicio/rechazarTermino.js @@ -58,7 +58,7 @@ const cancelar = async (body) => { ) .then((res) => Servicio.update( - { idStatus: 8, cartaTermino: null }, + { idStatus: 8, cartaTermino: '' }, { where: { idServicio } } ) ) diff --git a/server/controller/Usuario/escolares.js b/server/controller/Usuario/escolares.js index 5644a25..01dea13 100644 --- a/server/controller/Usuario/escolares.js +++ b/server/controller/Usuario/escolares.js @@ -16,7 +16,7 @@ const escolares = async (body) => { .then((res) => { if (!res.data.nombre || !res.data.carrconst || !res.data.avance) throw new Error( - 'El alumno no cumple con los requicitos para realizar el Servicio Social. Si cree que esto es erroneo comunicate con COESI.' + 'El alumno no cumple con los requisitos para realizar el Servicio Social. Si cree que esto es erroneo comunicate con COESI.' ); alumno = { nombre: res.data.nombre.trim(), diff --git a/server/db/capetasDrive.js b/server/db/capetasDrive.js index ba3ed58..864bb11 100644 --- a/server/db/capetasDrive.js +++ b/server/db/capetasDrive.js @@ -1,46 +1,71 @@ const drive = require('../helper/drive'); -const Usuario = require('../db/tablas/Usuario'); -const Servicio = require('../db/tablas/Servicio'); +const Usuario = require('./tablas/Usuario'); +const Servicio = require('./tablas/Servicio'); + +const buscarCarpetas = (array, numeroCuenta) => { + let arrayAux = []; + + for (let i = 0; i < array.length; i++) + if (array[i].name === numeroCuenta) arrayAux.push(array[i]); + return arrayAux; +}; + +const buscarArchivos = (array, idParent) => { + let arrayAux = []; + + for (let i = 0; i < array.length; i++) + if (array[i].parents[0] === idParent) arrayAux.push(array[i]); + return arrayAux; +}; const borrarCarpetas = async () => { - await Usuario.findAll({ where: { idTipoUsuario: 3 } }).then(async (res) => { - for (let i = 0; i < res.length; i++) { - let carpetasAlumno = await drive.buscarCarpetas(res[i].usuario); + const { pdf, carpetas } = await drive.archivosFicheros(); + console.log('Sa cargo todo el drive correctamente.'); + await Usuario.findAll({ where: { idTipoUsuario: 3 } }).then(async (res) => { + console.log(`Hay ${res.length} alumnos.`); + for (let i = 0; i < res.length; i++) { + let carpetasAlumno = buscarCarpetas(carpetas, res[i].usuario); + + console.log(`${(100 * (i + 1)) / res.length}%`); console.log( - `El numero de cuenta ${res[i].usuario} tiene ${carpetasAlumno.length} carpetas.` + `El numero de cuenta ${res[i].usuario} tiene ${ + carpetasAlumno.length + } carpeta${carpetasAlumno.length > 1 ? 's' : ''}.` ); if (carpetasAlumno.length > 0) { - for (let j = 0; j < carpetasAlumno.length; j++) { - let archivos = await drive.archivosCarpeta(carpetasAlumno[j].id); + console.log( + `La carpeta ${carpetasAlumno[0].name} con la que nos quedaremos es ${carpetasAlumno[0].id}.` + ); + await Servicio.update( + { carpeta: carpetasAlumno[0].id }, + { where: { idUsuario: res[i].idUsuario } } + ); + } + if (carpetasAlumno.length > 1) { + for (let j = 1; j < carpetasAlumno.length; j++) { + let archivosCarpeta = buscarArchivos(pdf, carpetasAlumno[j].id); console.log( - `La carpeta ${carpetasAlumno[j].name} con id ${carpetasAlumno[j].id} tiene ${carpetasAlumno[j].length} archivos.` + `La carpeta ${carpetasAlumno[j].id} tiene ${ + archivosCarpeta.length + } archivo${archivosCarpeta.length > 1 ? 's' : ''}.` ); - if (j > 0) { - for (let k = 0; k < archivos.length; k++) { - console.log( - `Se movio el archivo ${archivos[k].name} con id ${archivos[k].id} de la carpeta ${carpetasAlumno[j].id} a la carpeta ${carpetasAlumno[0].id}` - ); - // await drive.update( - // archivos[k].id, - // carpetasAlumno[0].id, - // carpetasAlumno[j].id - // ); - } - console.log(`Se borro la carpet ${carpetasAlumno[j].id}`); - // await drive.deleteFile(carpetasAlumno[j].id) + for (let k = 0; k < archivosCarpeta.length; k++) { + await drive.update( + archivosCarpeta[k].id, + carpetasAlumno[0].id, + carpetasAlumno[j].id + ); + console.log( + `Se movio el archivo ${archivosCarpeta[k].name} con id ${archivosCarpeta[k].id} de la carpeta ${carpetasAlumno[j].id} a la carpeta ${carpetasAlumno[0].id}.` + ); } + await drive.deleteFile(carpetasAlumno[j].id); + console.log(`Se elimino la carpeta con id ${carpetasAlumno[j].id}`); } - - // await Servicio.update( - // { carpeta: carpetasAlumno[0].id }, - // { where: { idUsuario: res[i].idUsuario } } - // ); } - console.log( - '------------------------------------------------------------------' - ); + console.log('------------------------------------------------------'); } }); }; diff --git a/server/db/hotfiexes.js b/server/db/hotfiexes.js new file mode 100644 index 0000000..f9c1f7c --- /dev/null +++ b/server/db/hotfiexes.js @@ -0,0 +1,48 @@ +const moment = require('moment'); +const Usuario = require('./tablas/Usuario'); +const Servicio = require('./tablas/Servicio'); + +const corregir = async () => { + const dosMilVeinte = moment('2020-01-01'); + + await Servicio.findAll({ include: [{ model: Usuario }] }).then((res) => { + for (let i = 0; i < res.length; i++) { + let fechaInicio = moment(res[i].fechaInicio); + let fechaFin = moment(res[i].fechaFin); + + if (fechaFin.year() < dosMilVeinte.year()) { + console.log( + `El servicio ${res[i].idServicio} del usario ${ + res[i].Usuario.usuario + } con id ${ + res[i].idUsuario + } tiene la fecha Fin mal ${fechaFin.year()} status ${res[i].idStatus}` + ); + } + if (fechaInicio.year() < dosMilVeinte.year()) { + console.log( + `El servicio ${res[i].idServicio} del usario ${ + res[i].Usuario.usuario + } con id ${ + res[i].idUsuario + } tiene la fecha inicio mal ${fechaInicio.year()} status ${ + res[i].idStatus + }` + ); + } + if ( + res[i].idStatus != 10 && + res[i].idStatus != 7 && + res[i].idStatus > 3 && + (!res[i].direccion || + !res[i].telefono || + !res[i].carpeta || + !res[i].fechaNacimiento) + ) { + console.log(res[i].dataValues); + } + } + }); +}; + +corregir(); diff --git a/server/helper/correos.js b/server/helper/correos.js index b405f91..435f4a7 100644 --- a/server/helper/correos.js +++ b/server/helper/correos.js @@ -5,7 +5,7 @@ const preRegistro = (password, nombre) => { subject: 'Notificación de Pre-Registro.', msj: `Estimado(a) ${nombre}: -Te informamos que la dependencia en donde decidiste realizar tu servicio social ya te registró en nuestro sistema de servicio social, por lo que para completar el proceso debes ingresar en un periodo máximo de 10 días hábiles a partir de la recepción de este mensaje, a la página _______ con tu número de cuenta y contraseña: ${password}, para llenar un formulario con tus datos. +Te informamos que la dependencia en donde decidiste realizar tu servicio social ya te registró en nuestro sistema de servicio social, por lo que para completar el proceso debes ingresar en un periodo máximo de 10 días hábiles a partir de la recepción de este mensaje, a la página https://iris.acatlan.unam.mx/ con tu número de cuenta y contraseña: ${password}, para llenar un formulario con tus datos. En caso de no realizar dicho registro, tu trámite queda inconcluso y no nos hacemos responsables por las horas de servicio social prestadas en cualquier dependencia. En el sistema que se te indicó podrás dar seguimiento al resto de tu trámite de servicio social. Cualquier duda puedes acudir al área de Registro y Control de Servicio Social en COESI de lunes a viernes de 10:00 a 13:00 hrs. y de 16:00 a 19:00 hrs. o bien, comunicarte al 5623 1686 o al correo tramites.ss@acatlan.unam.mx diff --git a/server/helper/diario.js b/server/helper/diario.js index 03b6631..1942a1b 100644 --- a/server/helper/diario.js +++ b/server/helper/diario.js @@ -4,65 +4,49 @@ const Usuario = require('../db/tablas/Usuario'); const Programa = require('../db/tablas/Programa'); const gmail = require('./gmail'); const correos = require('./correos'); -const { where } = require('sequelize/types'); const diario = async () => { + let mensaje = ''; const now = moment(); - let servicios = await Servicio.findAll({ + const servicios = await Servicio.findAll({ where: { idStatus: 3 }, include: [ { model: Usuario }, { model: Programa, include: [{ model: Usuario }] }, ], - }).then((res) => res); + }); - const mensajeRecordatorio = async () => { - for (let i = 0; i < 1; i++) { - let fechaFin = moment(servicios[i].fechaFin); - let fechaFinDate = fechaFin.dayOfYear(); + for (let i = 0; i < servicios.length; i++) { + let fechaFin = moment(servicios[i].fechaFin); + let fechaFinDate = fechaFin.dayOfYear(); - if (fechaFin.year() > now.year) - fechaFinDate += 365 * (fechaFin.year() - now.year()); + if (fechaFin.year() > now.year()) + fechaFinDate += 365 * (fechaFin.year() - now.year()); + if (fechaFinDate - now.dayOfYear() === 7) { + let correoAlumno = correos.avisoTerminoAlumno( + servicios[i].Usuario.nombre + ); + let correoResponsable = correos.avisoTerminoResponsable( + servicios[i].Usuario.nombre + ); - if (fechaFinDate - now.dayOfYear() === 7) { - let correoAlumno = correos.avisoTerminoAlumno( - servicios[i].Usuario.nombre - ); - let correoResponsable = correos.avisoTerminoResponsable( - servicios[i].Usuario.nombre - ); - - await gmail( - correoAlumno.subject, - servicios[i].correo, - correoAlumno.msj - ); - await gmail( - correoResponsable.subject, - servicios[i].correo, - correoResponsable.msj - ); - } + mensaje += `Se envio correo al alumno ${servicios[i].Usuario.usuario} con id ${servicios[i].Usuario.idUsuario} al correo ${servicios[i].correo} y al serviciosponsable ${servicios[i].Programa.Usuario.nombre} con id ${servicios[i].Programa.Usuario.idUsuario} y correo ${servicios[i].Programa.Usuario.usuario}\n`; + await gmail(correoAlumno.subject, servicios[i].correo, correoAlumno.msj); + await gmail( + correoResponsable.subject, + servicios[i].Programa.Usuario.usuario, + correoResponsable.msj + ); + } else if (fechaFinDate - now.dayOfYear() <= -1) { + mensaje += `El servicio con id ${servicios[i].idServicio} del alumno ${servicios[i].Usuario.usuario} con id ${servicios[i].Usuario.idUsuario} paso al status 4\n`; + await Servicio.update( + { idStatus: 4 }, + { where: { idServicio: servicios[i].idServicio } } + ); } - }; + } - const diaDespues = async () => { - for (let i = 0; i < servicios.length; i++) { - let fechaFin = moment(servicios[i].fechaFin); - let fechaFinDate = fechaFin.dayOfYear(); - - if (fechaFin.year() > now.year) - fechaFinDate += 365 * (fechaFin.year() - now.year()); - if (fechaFinDate - now.dayOfYear() <= -1) { - await Servicio.update( - { idStatus: 4 }, - { where: { idServicio: servicios[i].idServicio } } - ); - } - } - }; - - // mensajeRecordatorio(); + await gmail('Reporte función diario', 'lemuel@acatlan.unam.mx', mensaje); }; diario(); diff --git a/server/helper/drive.js b/server/helper/drive.js index c8c9802..2e85794 100644 --- a/server/helper/drive.js +++ b/server/helper/drive.js @@ -99,7 +99,7 @@ const list = (pageToken) => { supportsTeamDrives: true, includeTeamDriveItems: true, spaces: 'drive', - pageSize: 100, + pageSize: 1000, pageToken, fields: '*', orderBy: 'name', @@ -129,43 +129,6 @@ const update = (fileId, addParents, removeParents) => { }); }; -// Buscar carpeta -const buscarCarpetas = async (name) => { - const data = []; - let pageToken = ''; - - do { - let response = await list(pageToken); - let files = response.files; - - for (let i = 0; i < files.length; i++) - if ( - files[i].name === name //&& - // files[i].mimeType === 'application/vnd.google-apps.folder' - ) - data.push(files[i]); - if (response.nextPageToken) pageToken = response.nextPageToken; - else pageToken = ''; - } while (pageToken); - return data; -}; - -const archivosCarpeta = async (id) => { - let pageToken = ''; - const data = []; - - do { - let response = await list(pageToken); - let files = response.files; - - for (let i = 0; i < files.length; i++) - if (files[i].parents[0] === id) data.push(files[i]); - if (response.nextPageToken) pageToken = response.nextPageToken; - else pageToken = ''; - } while (pageToken); - return data; -}; - const folder = async (numeroCuenta) => { let pageToken = ''; @@ -195,11 +158,32 @@ const borrarTodo = () => { // borrarTodo(); +const archivosFicheros = async () => { + let pageToken = ''; + const pdf = []; + const carpetas = []; + + do { + let response = await list(pageToken); + + for (let i = 0; i < response.files.length; i++) { + if (response.files[i].mimeType === 'application/vnd.google-apps.folder') + carpetas.push(response.files[i]); + else pdf.push(response.files[i]); + } + if (response.nextPageToken) pageToken = response.nextPageToken; + else pageToken = ''; + } while (pageToken); + + return { pdf, carpetas }; +}; + +// archivosFicheros(); + module.exports = { folder, uploadFile, - buscarCarpetas, - archivosCarpeta, deleteFile, update, + archivosFicheros, }; diff --git a/server/helper/validar.js b/server/helper/validar.js index 382eb94..097018e 100644 --- a/server/helper/validar.js +++ b/server/helper/validar.js @@ -40,7 +40,22 @@ const validarCorreo = (correo) => { }; const caracteresEspeciales = (char) => { - const charset = [' ', '.', '-', ',', '/', '#', '?', '¿']; + const charset = [ + ' ', + '.', + '-', + ',', + '/', + '#', + '?', + '¿', + ':', + ';', + '"', + "'", + '_', + '\n', + ]; for (let i = 0; i < charset.length; i++) if (charset[i] === char) return true; return false;