reduccion de lineas de codigo
This commit is contained in:
@@ -6,10 +6,12 @@ const CuestionarioAlumno = require('../../db/tablas/CuestionarioAlumno');
|
||||
const Servicio = require('../../db/tablas/Servicio');
|
||||
const Programa = require('../../db/tablas/Programa');
|
||||
const Usuario = require('../../db/tablas/Usuario');
|
||||
const { EROFS } = require('constants');
|
||||
|
||||
const get = async (body) => {
|
||||
let year = validar.validarNumero(body.year, 4);
|
||||
let path = `csv/${year}_cuestionario_alumno.csv`;
|
||||
const year = validar.validarNumero(body.year, 4);
|
||||
const path = `csv/${year}_cuestionario_alumno.csv`;
|
||||
const data = [];
|
||||
|
||||
return Servicio.findAll({
|
||||
include: [
|
||||
@@ -21,9 +23,6 @@ const get = async (body) => {
|
||||
{ model: Usuario },
|
||||
],
|
||||
}).then((res) => {
|
||||
let data = [];
|
||||
let csvString = '';
|
||||
|
||||
for (let i = 0; i < res.length; i++)
|
||||
data.push({
|
||||
idServicio: res[i].idServicio,
|
||||
@@ -68,13 +67,14 @@ const get = async (body) => {
|
||||
});
|
||||
try {
|
||||
fs.unlinkSync(path);
|
||||
} catch (err) {}
|
||||
csvString = convertArrayToCSV(data);
|
||||
fs.appendFile(path, csvString, (err) => {
|
||||
} catch (err) {
|
||||
throw new Error(err);
|
||||
}
|
||||
fs.appendFile(path, convertArrayToCSV(data), (err) => {
|
||||
if (err) throw new Error(err);
|
||||
});
|
||||
return {
|
||||
message: `Se creo/actualizo correctamente el csv del cuestionario de programa del año ${year}`,
|
||||
message: `Se creo/actualizo correctamente el csv del cuestionario de alumno del año ${year}.`,
|
||||
};
|
||||
});
|
||||
};
|
||||
|
||||
@@ -3,30 +3,30 @@ const CuestionarioAlumno = require('../../db/tablas/CuestionarioAlumno');
|
||||
const Servicio = require('../../db/tablas/Servicio');
|
||||
|
||||
const nuevo = async (body) => {
|
||||
let idServicio = validar.validarId(body.idServicio);
|
||||
let sexo = body.sexo;
|
||||
let edad = body.edad;
|
||||
let servicioMedico = body.servicioMedico;
|
||||
let p1 = body.p1;
|
||||
let p2 = body.p2;
|
||||
let p4 = body.p4;
|
||||
let p6 = body.p6;
|
||||
let p7 = body.p7;
|
||||
let p9 = body.p9;
|
||||
let p10 = body.p10;
|
||||
let p11 = body.p11;
|
||||
let p12 = body.p12;
|
||||
let p13 = body.p13;
|
||||
let p16 = body.p16;
|
||||
let p18 = body.p18;
|
||||
let p19 = body.p19;
|
||||
let p20 = body.p20;
|
||||
let p25 = body.p25;
|
||||
let p26 = body.p26;
|
||||
let p27 = body.p27;
|
||||
let p28 = body.p28;
|
||||
let p29 = body.p29;
|
||||
let p30 = body.p30;
|
||||
const idServicio = validar.validarId(body.idServicio);
|
||||
const sexo = body.sexo;
|
||||
const edad = body.edad;
|
||||
const servicioMedico = body.servicioMedico;
|
||||
const p1 = body.p1;
|
||||
const p2 = body.p2;
|
||||
const p4 = body.p4;
|
||||
const p6 = body.p6;
|
||||
const p7 = body.p7;
|
||||
const p9 = body.p9;
|
||||
const p10 = body.p10;
|
||||
const p11 = body.p11;
|
||||
const p12 = body.p12;
|
||||
const p13 = body.p13;
|
||||
const p16 = body.p16;
|
||||
const p18 = body.p18;
|
||||
const p19 = body.p19;
|
||||
const p20 = body.p20;
|
||||
const p25 = body.p25;
|
||||
const p26 = body.p26;
|
||||
const p27 = body.p27;
|
||||
const p28 = body.p28;
|
||||
const p29 = body.p29;
|
||||
const p30 = body.p30;
|
||||
let p3 = '';
|
||||
let p5 = '';
|
||||
let p8 = '';
|
||||
|
||||
@@ -8,8 +8,9 @@ const Programa = require('../../db/tablas/Programa');
|
||||
const Usuario = require('../../db/tablas/Usuario');
|
||||
|
||||
const get = async (body) => {
|
||||
let year = validar.validarNumero(body.year, 4);
|
||||
let path = `csv/${year}_cuestionario_programa.csv`;
|
||||
const year = validar.validarNumero(body.year, 4);
|
||||
const path = `csv/${year}_cuestionario_programa.csv`;
|
||||
const data = [];
|
||||
|
||||
return Servicio.findAll({
|
||||
include: [
|
||||
@@ -21,9 +22,6 @@ const get = async (body) => {
|
||||
{ model: Usuario },
|
||||
],
|
||||
}).then((res) => {
|
||||
let data = [];
|
||||
let csvString = '';
|
||||
|
||||
for (let i = 0; i < res.length; i++)
|
||||
data.push({
|
||||
idServicio: res[i].idServicio,
|
||||
@@ -44,13 +42,14 @@ const get = async (body) => {
|
||||
});
|
||||
try {
|
||||
fs.unlinkSync(path);
|
||||
} catch (err) {}
|
||||
csvString = convertArrayToCSV(data);
|
||||
fs.appendFile(path, csvString, (err) => {
|
||||
} catch (err) {
|
||||
throw new Error(err);
|
||||
}
|
||||
fs.appendFile(path, convertArrayToCSV(data), (err) => {
|
||||
if (err) throw new Error(err);
|
||||
});
|
||||
return {
|
||||
message: `Se creo/actualizo correctamente el csv del cuestionario de programa del año ${year}`,
|
||||
message: `Se creo/actualizo correctamente el csv del cuestionario de programa del año ${year}.`,
|
||||
};
|
||||
});
|
||||
};
|
||||
|
||||
@@ -3,15 +3,15 @@ const CuestionarioPrograma = require('../../db/tablas/CuestionarioPrograma');
|
||||
const Servicio = require('../../db/tablas/Servicio');
|
||||
|
||||
const nuevo = async (body) => {
|
||||
let idServicio = validar.validarId(body.idServicio);
|
||||
let actividad1 = body.actividad1;
|
||||
let actividad2 = body.actividad2;
|
||||
let actividad3 = body.actividad3;
|
||||
let actividad4 = body.actividad4;
|
||||
let actividad5 = body.actividad5;
|
||||
const idServicio = validar.validarId(body.idServicio);
|
||||
const actividad1 = body.actividad1;
|
||||
const actividad2 = body.actividad2;
|
||||
const actividad3 = body.actividad3;
|
||||
const actividad4 = body.actividad4;
|
||||
const actividad5 = body.actividad5;
|
||||
const p6 = body.p6;
|
||||
const p7 = body.p7;
|
||||
let retroalimentacion = '';
|
||||
let p6 = body.p6;
|
||||
let p7 = body.p7;
|
||||
|
||||
for (let i = 0; i < body.retroalimentacion.length; i++) {
|
||||
retroalimentacion += body.retroalimentacion[i];
|
||||
|
||||
@@ -3,7 +3,7 @@ const Programa = require('../../db/tablas/Programa');
|
||||
const Usuario = require('../../db/tablas/Usuario');
|
||||
|
||||
const programasAdmin = async (body) => {
|
||||
let idUsuario = validar.validarId(body.idUsuario);
|
||||
const idUsuario = validar.validarId(body.idUsuario);
|
||||
|
||||
return Usuario.findOne({
|
||||
where: { idUsuario },
|
||||
|
||||
@@ -3,7 +3,7 @@ const Programa = require('../../db/tablas/Programa');
|
||||
const Usuario = require('../../db/tablas/Usuario');
|
||||
|
||||
const programasResponsable = async (body) => {
|
||||
let idUsuario = validar.validarId(body.idUsuario);
|
||||
const idUsuario = validar.validarId(body.idUsuario);
|
||||
|
||||
return Usuario.findOne({
|
||||
where: { idUsuario },
|
||||
|
||||
@@ -7,7 +7,7 @@ const Status = require('../../db/tablas/Status');
|
||||
const Programa = require('../../db/tablas/Programa');
|
||||
|
||||
const admin = async (body) => {
|
||||
let idServicio = validar.validarId(body.idServicio);
|
||||
const idServicio = validar.validarId(body.idServicio);
|
||||
|
||||
return Servicio.findOne({
|
||||
where: { idServicio },
|
||||
@@ -19,51 +19,13 @@ const admin = async (body) => {
|
||||
],
|
||||
}).then((res) => {
|
||||
if (!res) throw new Error('No existe este servicio social.');
|
||||
return {
|
||||
idServicio: res.idServicio,
|
||||
creditos: res.creditos,
|
||||
correo: res.correo,
|
||||
telefono: res.telefono,
|
||||
direccion: res.direccion,
|
||||
fechaInicio: res.fechaInicio,
|
||||
fechaFin: res.fechaFin,
|
||||
fechaNacimiento: res.fechaNacimiento,
|
||||
cartaAceptacion: res.cartaAceptacion,
|
||||
cartaTermino: res.cartaTermino,
|
||||
informeGlobal: res.informeGlobal,
|
||||
programaInterno: res.programaInterno,
|
||||
profesor: res.profesor,
|
||||
vistoBuenoAcatlan: res.vistoBuenoAcatlan,
|
||||
createdAt: res.createdAt,
|
||||
updatedAt: res.updatedAt,
|
||||
idCuestionarioAlumno: res.idCuestionarioAlumno,
|
||||
idCuestionarioPrograma: res.idCuestionarioPrograma,
|
||||
Usuario: {
|
||||
idUsuario: res.Usuario.idUsuario,
|
||||
usuario: res.Usuario.usuario,
|
||||
nombre: res.Usuario.nombre,
|
||||
TipoUsuario: {
|
||||
idTipoUsuario: res.Usuario.TipoUsuario.idTipoUsuario,
|
||||
tipoUsuario: res.Usuario.TipoUsuario.tipoUsuario,
|
||||
},
|
||||
},
|
||||
Carrera: {
|
||||
idCarrera: res.Carrera.idCarrera,
|
||||
carrera: res.Carrera.carrera,
|
||||
},
|
||||
Status: {
|
||||
idStatus: res.Status.idStatus,
|
||||
status: res.Status.status,
|
||||
},
|
||||
Programa: {
|
||||
idPrograma: res.Programa.idPrograma,
|
||||
institucion: res.Programa.institucion,
|
||||
dependencia: res.Programa.dependencia,
|
||||
programa: res.Programa.programa,
|
||||
clavePrograma: res.Programa.clavePrograma,
|
||||
acatlan: res.Programa.acatlan,
|
||||
},
|
||||
};
|
||||
delete res.dataValues.Usuario.dataValues.password;
|
||||
delete res.dataValues.Programa.dataValues.idUsuario;
|
||||
delete res.dataValues.idUsuario;
|
||||
delete res.dataValues.idCarrera;
|
||||
delete res.dataValues.idStatus;
|
||||
delete res.dataValues.idPrograma;
|
||||
return res;
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
@@ -13,52 +13,26 @@ const alumno = async (body) => {
|
||||
.then((res) => {
|
||||
if (!res) throw new Error('No existe este usuario.');
|
||||
if (res.idTipoUsuario !== 3)
|
||||
throw new Error('No es un usuaior de tipo alumno.');
|
||||
throw new Error('No es un usuario de tipo alumno.');
|
||||
return Servicio.findOne({
|
||||
where: { idUsuario, idStatus: { [Op.not]: 10 } },
|
||||
include: [
|
||||
{ model: Usuario },
|
||||
{ model: Carrera },
|
||||
{ model: Status },
|
||||
{ model: Programa },
|
||||
],
|
||||
include: [{ model: Carrera }, { model: Status }, { model: Programa }],
|
||||
});
|
||||
})
|
||||
.then((res) => {
|
||||
if (!res) throw new Error('No existe este servicio social.');
|
||||
return {
|
||||
idServicio: res.idServicio,
|
||||
creditos: res.creditos,
|
||||
correo: res.correo,
|
||||
telefono: res.telefono,
|
||||
direccion: res.direccion,
|
||||
fechaInicio: res.fechaInicio,
|
||||
fechaFin: res.fechaFin,
|
||||
fechaNacimiento: res.fechaNacimiento,
|
||||
informeGlobal: res.informeGlobal,
|
||||
programaInterno: res.programaInterno,
|
||||
profesor: res.profesor,
|
||||
createdAt: res.createdAt,
|
||||
updatedAt: res.updatedAt,
|
||||
idCuestionarioAlumno: res.idCuestionarioAlumno,
|
||||
Carrera: {
|
||||
idCarrera: res.Carrera.idCarrera,
|
||||
carrera: res.Carrera.carrera,
|
||||
},
|
||||
Status: {
|
||||
idStatus: res.Status.idStatus,
|
||||
status: res.Status.status,
|
||||
},
|
||||
Programa: {
|
||||
idPrograma: res.Programa.idPrograma,
|
||||
institucion: res.Programa.institucion,
|
||||
dependencia: res.Programa.dependencia,
|
||||
programa: res.Programa.programa,
|
||||
clavePrograma: res.Programa.clavePrograma,
|
||||
acatlan: res.Programa.acatlan,
|
||||
activo: res.Programa.activo,
|
||||
},
|
||||
};
|
||||
delete res.dataValues.idUsuario;
|
||||
delete res.dataValues.idCarrera;
|
||||
delete res.dataValues.idStatus;
|
||||
delete res.dataValues.idPrograma;
|
||||
delete res.dataValues.updatedAt;
|
||||
delete res.dataValues.carpeta;
|
||||
delete res.dataValues.cartaAceptacion;
|
||||
delete res.dataValues.cartaTermino;
|
||||
delete res.dataValues.vistoBuenoAcatlan;
|
||||
delete res.dataValues.idCuestionarioPrograma;
|
||||
delete res.dataValues.Programa.idUsuario;
|
||||
return res;
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
@@ -6,8 +6,8 @@ const Usuario = require('../../db/tablas/Usuario');
|
||||
const Programa = require('../../db/tablas/Programa');
|
||||
|
||||
const cancelar = async (body) => {
|
||||
let idServicio = validar.validarId(body.idServicio);
|
||||
let mensaje = validar.validarAlfanumerico(body.mensaje, 'El mensaje', 800);
|
||||
const idServicio = validar.validarId(body.idServicio);
|
||||
const mensaje = validar.validarAlfanumerico(body.mensaje, 'El mensaje', 800);
|
||||
let correoResponsable = {};
|
||||
let correoAlumno = {};
|
||||
let emailResponsable = '';
|
||||
|
||||
@@ -3,8 +3,8 @@ const drive = require('../../helper/drive');
|
||||
const Servicio = require('../../db/tablas/Servicio');
|
||||
|
||||
const cartaTermino = async (body, file) => {
|
||||
let idServicio = validar.validarId(body.idServicio);
|
||||
let path = `./server/uploads/${validar.validar(file, 'El archivo', 1000)}`;
|
||||
const idServicio = validar.validarId(body.idServicio);
|
||||
const path = `./server/uploads/${validar.validar(file, 'El archivo', 1000)}`;
|
||||
|
||||
return Servicio.findOne({
|
||||
where: { idServicio },
|
||||
|
||||
@@ -3,8 +3,8 @@ const drive = require('../../helper/drive');
|
||||
const Servicio = require('../../db/tablas/Servicio');
|
||||
|
||||
const cartaTermino = async (body, file) => {
|
||||
let idServicio = validar.validarId(body.idServicio);
|
||||
let path = `./server/uploads/${validar.validar(file, 'El archivo', 1000)}`;
|
||||
const idServicio = validar.validarId(body.idServicio);
|
||||
const path = `./server/uploads/${validar.validar(file, 'El archivo', 1000)}`;
|
||||
|
||||
return Servicio.findOne({
|
||||
where: { idServicio },
|
||||
|
||||
@@ -3,8 +3,8 @@ const drive = require('../../helper/drive');
|
||||
const Servicio = require('../../db/tablas/Servicio');
|
||||
|
||||
const informeGlobal = async (body, file) => {
|
||||
let idServicio = validar.validarId(body.idServicio);
|
||||
let path = `./server/uploads/${validar.validar(file, 'El archivo', 1000)}`;
|
||||
const idServicio = validar.validarId(body.idServicio);
|
||||
const path = `./server/uploads/${validar.validar(file, 'El archivo', 1000)}`;
|
||||
|
||||
return Servicio.findOne({
|
||||
where: { idServicio },
|
||||
|
||||
@@ -6,9 +6,9 @@ const Usuario = require('../../db/tablas/Usuario');
|
||||
const Programa = require('../../db/tablas/Programa');
|
||||
|
||||
const liberacion = async (body) => {
|
||||
let idServicio = validar.validarId(body.idServicio);
|
||||
const idServicio = validar.validarId(body.idServicio);
|
||||
const update = { idStatus: 6 };
|
||||
let correo = {};
|
||||
let update = { idStatus: 6 };
|
||||
|
||||
return Servicio.findOne({
|
||||
where: { idServicio },
|
||||
@@ -16,10 +16,10 @@ const liberacion = async (body) => {
|
||||
})
|
||||
.then(async (res) => {
|
||||
if (!res) throw new Error('No existe este Servicio Social.');
|
||||
// if (res.Programa.acatlan && !body.vistoBuenoAcatlan)
|
||||
// throw new Error(
|
||||
// 'El programa de este Servicio Social es Acatlán Contigo y no se envio la variable validando este servicio.'
|
||||
// );
|
||||
if (res.Programa.acatlan && !body.vistoBuenoAcatlan)
|
||||
throw new Error(
|
||||
'El programa de este Servicio Social es Acatlán Contigo y no se envio la variable validando este servicio.'
|
||||
);
|
||||
switch (res.idStatus) {
|
||||
case 5:
|
||||
correo = correos.terminoValidado(res.Usuario.nombre);
|
||||
|
||||
@@ -7,26 +7,26 @@ const Carrera = require('../../db/tablas/Carrera');
|
||||
const validar = require('../../helper/validar');
|
||||
|
||||
const nuevo = async (body, file) => {
|
||||
let idUsuario = validar.validarId(body.idUsuario);
|
||||
let idPrograma = validar.validarId(body.idPrograma);
|
||||
let idCarrera = validar.validarId(body.idCarrera);
|
||||
let numeroCuenta = validar.validarNumeroCuenta(body.numeroCuenta);
|
||||
let creditos = validar.validarNumero(body.creditos);
|
||||
let correo = validar.validarCorreo(body.correo);
|
||||
let fechaInicio = validar.validarFecha(body.fechaInicio);
|
||||
let fechaFin = validar.validarFecha(body.fechaFin);
|
||||
let path = `./server/uploads/${validar.validar(file, 'El archivo', 1000)}`;
|
||||
let carpeta = '';
|
||||
let programaInterno = body.programaInterno
|
||||
const idUsuario = validar.validarId(body.idUsuario);
|
||||
const idPrograma = validar.validarId(body.idPrograma);
|
||||
const idCarrera = validar.validarId(body.idCarrera);
|
||||
const numeroCuenta = validar.validarNumeroCuenta(body.numeroCuenta);
|
||||
const creditos = validar.validarNumero(body.creditos);
|
||||
const correo = validar.validarCorreo(body.correo);
|
||||
const fechaInicio = validar.validarFecha(body.fechaInicio);
|
||||
const fechaFin = validar.validarFecha(body.fechaFin);
|
||||
const path = `./server/uploads/${validar.validar(file, 'El archivo', 1000)}`;
|
||||
const programaInterno = body.programaInterno
|
||||
? validar.validarTexto(
|
||||
body.programaInterno,
|
||||
'El texto programa interno.',
|
||||
80
|
||||
)
|
||||
: '';
|
||||
let profesor = body.profesor
|
||||
const profesor = body.profesor
|
||||
? validar.validarTexto(body.profesor, 'El texto de profesor.', 50)
|
||||
: '';
|
||||
let carpeta = '';
|
||||
|
||||
return Usuario.findOne({
|
||||
where: { idUsuario },
|
||||
|
||||
@@ -6,8 +6,8 @@ const Usuario = require('../../db/tablas/Usuario');
|
||||
const Programa = require('../../db/tablas/Programa');
|
||||
|
||||
const cancelar = async (body) => {
|
||||
let idServicio = validar.validarId(body.idServicio);
|
||||
let mensaje = validar.validarAlfanumerico(body.mensaje, 'El mensaje', 800);
|
||||
const idServicio = validar.validarId(body.idServicio);
|
||||
const mensaje = validar.validarAlfanumerico(body.mensaje, 'El mensaje', 800);
|
||||
let correoResponsable = {};
|
||||
let correoAlumno = {};
|
||||
let emailResponsable = '';
|
||||
@@ -57,7 +57,7 @@ const cancelar = async (body) => {
|
||||
)
|
||||
.then((res) =>
|
||||
Servicio.update(
|
||||
{ idStatus: 7, cartaAceptacion: '' },
|
||||
{ idStatus: 7, cartaAceptacion: null },
|
||||
{ where: { idServicio } }
|
||||
)
|
||||
)
|
||||
|
||||
@@ -6,8 +6,8 @@ const Usuario = require('../../db/tablas/Usuario');
|
||||
const Programa = require('../../db/tablas/Programa');
|
||||
|
||||
const cancelar = async (body) => {
|
||||
let idServicio = validar.validarId(body.idServicio);
|
||||
let mensaje = validar.validarAlfanumerico(body.mensaje, 'El mensaje', 800);
|
||||
const idServicio = validar.validarId(body.idServicio);
|
||||
const mensaje = validar.validarAlfanumerico(body.mensaje, 'El mensaje', 800);
|
||||
let correoResponsable = {};
|
||||
let correoAlumno = {};
|
||||
let emailResponsable = '';
|
||||
@@ -58,7 +58,7 @@ const cancelar = async (body) => {
|
||||
)
|
||||
.then((res) =>
|
||||
Servicio.update(
|
||||
{ idStatus: 9, informeGlobal: '' },
|
||||
{ idStatus: 9, informeGlobal: null },
|
||||
{ where: { idServicio } }
|
||||
)
|
||||
)
|
||||
|
||||
@@ -6,8 +6,8 @@ const Usuario = require('../../db/tablas/Usuario');
|
||||
const Programa = require('../../db/tablas/Programa');
|
||||
|
||||
const cancelar = async (body) => {
|
||||
let idServicio = validar.validarId(body.idServicio);
|
||||
let mensaje = validar.validarAlfanumerico(body.mensaje, 'El mensaje', 800);
|
||||
const idServicio = validar.validarId(body.idServicio);
|
||||
const mensaje = validar.validarAlfanumerico(body.mensaje, 'El mensaje', 800);
|
||||
let correoResponsable = {};
|
||||
let correoAlumno = {};
|
||||
let emailResponsable = '';
|
||||
@@ -58,7 +58,7 @@ const cancelar = async (body) => {
|
||||
)
|
||||
.then((res) =>
|
||||
Servicio.update(
|
||||
{ idStatus: 8, cartaTermino: '' },
|
||||
{ idStatus: 8, cartaTermino: null },
|
||||
{ where: { idServicio } }
|
||||
)
|
||||
)
|
||||
|
||||
@@ -6,8 +6,8 @@ const Servicio = require('../../db/tablas/Servicio');
|
||||
const Usuario = require('../../db/tablas/Usuario');
|
||||
|
||||
const registro = async (body) => {
|
||||
let idServicio = validar.validarId(body.idServicio);
|
||||
let password = '';
|
||||
const idServicio = validar.validarId(body.idServicio);
|
||||
const password = encriptar.generarPassword();
|
||||
let correo = {};
|
||||
let idUsuario;
|
||||
|
||||
@@ -20,7 +20,6 @@ const registro = async (body) => {
|
||||
|
||||
switch (res.idStatus) {
|
||||
case 1:
|
||||
password = encriptar.generarPassword();
|
||||
correo = correos.preRegistro(password, res.Usuario.nombre);
|
||||
idUsuario = res.idUsuario;
|
||||
return gmail(correo.subject, res.correo, correo.msj);
|
||||
|
||||
@@ -6,10 +6,10 @@ const Usuario = require('../../db/tablas/Usuario');
|
||||
const Programa = require('../../db/tablas/Programa');
|
||||
|
||||
const registroValidado = async (body) => {
|
||||
let idServicio = validar.validarId(body.idServicio);
|
||||
let fechaNacimiento = validar.validarFecha(body.fechaNacimiento);
|
||||
let telefono = validar.validarNumero(body.telefono, 15);
|
||||
let direccion = validar.validarAlfanumerico(
|
||||
const idServicio = validar.validarId(body.idServicio);
|
||||
const fechaNacimiento = validar.validarFecha(body.fechaNacimiento);
|
||||
const telefono = validar.validarNumero(body.telefono, 15);
|
||||
const direccion = validar.validarAlfanumerico(
|
||||
body.direccion,
|
||||
'La dirección',
|
||||
200
|
||||
@@ -67,7 +67,9 @@ const registroValidado = async (body) => {
|
||||
)
|
||||
.then((res) =>
|
||||
Servicio.update(
|
||||
// Producción
|
||||
// { idStatus: 3, direccion, telefono, fechaNacimiento },
|
||||
// Pruebas
|
||||
{ idStatus: 4, direccion, telefono, fechaNacimiento },
|
||||
{ where: { idServicio } }
|
||||
)
|
||||
|
||||
@@ -7,18 +7,18 @@ const Status = require('../../db/tablas/Status');
|
||||
const TipoUsuario = require('../../db/tablas/TipoUsuario');
|
||||
|
||||
const serviciosAdmin = async (body) => {
|
||||
let pagina = validar.validarId(body.pagina);
|
||||
let idStatus = body.idStatus ? validar.validarId(body.idStatus) : null;
|
||||
let nombre = body.nombre
|
||||
const pagina = validar.validarId(body.pagina);
|
||||
const where = body.idStatus
|
||||
? { idStatus: validar.validarId(body.idStatus) }
|
||||
: {};
|
||||
const nombre = body.nombre
|
||||
? validar.validarTexto(body.nombre, 'El nombre', 60)
|
||||
: '';
|
||||
let numeroCuenta = body.numeroCuenta
|
||||
const numeroCuenta = body.numeroCuenta
|
||||
? validar.validarNumeroCuenta(body.numeroCuenta)
|
||||
: '';
|
||||
let where = {};
|
||||
let data = [];
|
||||
const data = [];
|
||||
|
||||
if (idStatus) where.idStatus = idStatus;
|
||||
return Servicio.findAll({
|
||||
where,
|
||||
include: [
|
||||
@@ -45,19 +45,10 @@ const serviciosAdmin = async (body) => {
|
||||
idUsuario: res[i].Usuario.idUsuario,
|
||||
usuario: res[i].Usuario.usuario,
|
||||
nombre: res[i].Usuario.nombre,
|
||||
TipoUsuario: {
|
||||
idTipoUsuario: res[i].Usuario.TipoUsuario.idTipoUsuario,
|
||||
tipoUsuario: res[i].Usuario.TipoUsuario.tipoUsuario,
|
||||
},
|
||||
},
|
||||
Carrera: {
|
||||
idCarrera: res[i].Carrera.idCarrera,
|
||||
carrera: res[i].Carrera.carrera,
|
||||
},
|
||||
Status: {
|
||||
idStatus: res[i].Status.idStatus,
|
||||
status: res[i].Status.status,
|
||||
TipoUsuario: res[i].Usuario.TipoUsuario,
|
||||
},
|
||||
Carrera: res[i].Carrera,
|
||||
Status: res[i].Status,
|
||||
});
|
||||
return {
|
||||
registros: res.length,
|
||||
|
||||
@@ -8,19 +8,20 @@ const TipoUsuario = require('../../db/tablas/TipoUsuario');
|
||||
const Programa = require('../../db/tablas/Programa');
|
||||
|
||||
const serviciosResponsable = async (body) => {
|
||||
let pagina = validar.validarId(body.pagina);
|
||||
let idUsuario = validar.validarId(body.idUsuario);
|
||||
let idStatus = body.idStatus ? validar.validarId(body.idStatus) : null;
|
||||
let nombre = body.nombre
|
||||
const pagina = validar.validarId(body.pagina);
|
||||
const idUsuario = validar.validarId(body.idUsuario);
|
||||
const where = body.idStatus
|
||||
? { idStatus: validar.validarId(body.idStatus) }
|
||||
: {};
|
||||
|
||||
const nombre = body.nombre
|
||||
? validar.validarTexto(body.nombre, 'El nombre', 60)
|
||||
: '';
|
||||
let numeroCuenta = body.numeroCuenta
|
||||
const numeroCuenta = body.numeroCuenta
|
||||
? validar.validarNumeroCuenta(body.numeroCuenta)
|
||||
: '';
|
||||
let where = { [Op.and]: [{ idStatus: { [Op.ne]: 10 } }] };
|
||||
let data = [];
|
||||
const data = [];
|
||||
|
||||
if (idStatus) where[Op.and].push({ idStatus });
|
||||
return Usuario.findOne({ where: { idUsuario } })
|
||||
.then((res) => {
|
||||
if (!res) throw new Error('No existe este usuario.');
|
||||
@@ -56,19 +57,10 @@ const serviciosResponsable = async (body) => {
|
||||
idUsuario: res[i].Usuario.idUsuario,
|
||||
usuario: res[i].Usuario.usuario,
|
||||
nombre: res[i].Usuario.nombre,
|
||||
TipoUsuario: {
|
||||
idTipoUsuario: res[i].Usuario.TipoUsuario.idTipoUsuario,
|
||||
tipoUsuario: res[i].Usuario.TipoUsuario.tipoUsuario,
|
||||
},
|
||||
},
|
||||
Carrera: {
|
||||
idCarrera: res[i].Carrera.idCarrera,
|
||||
carrera: res[i].Carrera.carrera,
|
||||
},
|
||||
Status: {
|
||||
idStatus: res[i].Status.idStatus,
|
||||
status: res[i].Status.status,
|
||||
TipoUsuario: res[i].Usuario.TipoUsuario,
|
||||
},
|
||||
Carrera: res[i].Carrera,
|
||||
Status: res[i].Status,
|
||||
});
|
||||
return {
|
||||
registros: res.length,
|
||||
|
||||
@@ -1,17 +1,14 @@
|
||||
const drive = require('../../helper/drive');
|
||||
const validar = require('../../helper/validar');
|
||||
const Servicio = require('../../db/tablas/Servicio');
|
||||
const Usuario = require('../../db/tablas/Usuario');
|
||||
|
||||
const update = async (body, files) => {
|
||||
let idServicio = validar.validarId(body.idServicio);
|
||||
let dataUpdate = {};
|
||||
console.log('hola2');
|
||||
const idServicio = validar.validarId(body.idServicio);
|
||||
const dataUpdate = {};
|
||||
|
||||
return Servicio.findOne({ where: { idServicio } })
|
||||
.then(async (res) => {
|
||||
if (!res) throw new Error('Este Servicio Social no existe en la db.');
|
||||
|
||||
try {
|
||||
if (files['cartaAceptacion'][0].filename)
|
||||
dataUpdate.cartaAceptacion = await drive.uploadFile(
|
||||
@@ -54,7 +51,6 @@ const update = async (body, files) => {
|
||||
);
|
||||
if (body.telefono)
|
||||
dataUpdate.telefono = validar.validarNumero(body.telefono, 15);
|
||||
|
||||
if (validar.isObjectEmpty(dataUpdate))
|
||||
throw new Error(
|
||||
'No se envio nada para actualizar este Servicio Social'
|
||||
|
||||
@@ -1,9 +1,5 @@
|
||||
const Status = require('../../db/tablas/Status');
|
||||
|
||||
const get = () => {
|
||||
return Status.findAll().then((res) => {
|
||||
return res;
|
||||
});
|
||||
};
|
||||
const get = () => Status.findAll();
|
||||
|
||||
module.exports = get;
|
||||
|
||||
@@ -16,6 +16,7 @@ const escolares = async (body) => {
|
||||
.then((res) => {
|
||||
let data = res.data;
|
||||
|
||||
// console.log(res);
|
||||
if (!data.nombre || !data.carrconst || !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.'
|
||||
|
||||
@@ -5,28 +5,28 @@ const Usuario = require('../../db/tablas/Usuario');
|
||||
const TipoUsuario = require('../../db/tablas/TipoUsuario');
|
||||
|
||||
const login = async (body) => {
|
||||
let usuario = validar.validar(body.usuario, 'El usuario', 60);
|
||||
let password = validar.validarAlfanumerico(body.password, 'El password', 20);
|
||||
const usuario = validar.validar(body.usuario, 'El usuario', 60);
|
||||
const password = validar.validarAlfanumerico(
|
||||
body.password,
|
||||
'El password',
|
||||
20
|
||||
);
|
||||
|
||||
return Usuario.findOne({
|
||||
where: { usuario, activo: true },
|
||||
where: { usuario },
|
||||
include: [{ model: TipoUsuario }],
|
||||
}).then((res) => {
|
||||
if (!res) throw new Error('No existe este usuario.');
|
||||
if (!res.activo) throw new Error('Este usuario no esta activo.');
|
||||
if (encriptar.comparar(password, res.password)) {
|
||||
delete res.dataValues.password;
|
||||
delete res.dataValues.activo;
|
||||
return {
|
||||
Usuario: {
|
||||
idUsuario: res.idUsuario,
|
||||
usuario: res.usuario,
|
||||
nombre: res.nombre,
|
||||
TipoUsuario: {
|
||||
idTipoUsuario: res.TipoUsuario.idTipoUsuario,
|
||||
tipoUsuario: res.TipoUsuario.tipoUsuario,
|
||||
},
|
||||
},
|
||||
Usuario: res,
|
||||
token: crearToken(res.idUsuario),
|
||||
};
|
||||
}
|
||||
throw new Error('La contraseña es incorrecta');
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
@@ -6,9 +6,10 @@ const Usuario = require('../../db/tablas/Usuario');
|
||||
const Servicio = require('../../db/tablas/Servicio');
|
||||
|
||||
const newPasswordAlumno = async (body) => {
|
||||
let idServicio = await validar.validarId(body.idServicio);
|
||||
let password = encriptar.generarPassword();
|
||||
const idServicio = validar.validarId(body.idServicio);
|
||||
const password = encriptar.generarPassword();
|
||||
let idUsuario;
|
||||
let correo = {};
|
||||
|
||||
return Servicio.findOne({
|
||||
where: { idServicio },
|
||||
@@ -18,18 +19,16 @@ const newPasswordAlumno = async (body) => {
|
||||
if (!res) throw new Error('No existe este Servicio Social.');
|
||||
if (res.Usuario.idTipoUsuario != 3)
|
||||
throw new Error('Este usuario no es de tipo alumno.');
|
||||
|
||||
let correo = correos.preRegistro(password, res.Usuario.nombre);
|
||||
|
||||
correo = correos.preRegistro(password, res.Usuario.nombre);
|
||||
idUsuario = res.idUsuario;
|
||||
return gmail(correo.subject, res.correo, correo.msj);
|
||||
})
|
||||
.then((res) => {
|
||||
return Usuario.update(
|
||||
.then((res) =>
|
||||
Usuario.update(
|
||||
{ password: encriptar.encriptar(password) },
|
||||
{ where: { idUsuario } }
|
||||
);
|
||||
})
|
||||
)
|
||||
)
|
||||
.then((res) => {
|
||||
return {
|
||||
message: 'Se envio un correo con una contraseña nueva al alumno.',
|
||||
|
||||
@@ -5,25 +5,24 @@ const validar = require('../../helper/validar');
|
||||
const Usuario = require('../../db/tablas/Usuario');
|
||||
|
||||
const newPasswordResponsable = async (body) => {
|
||||
let idUsuario = await validar.validarId(body.idUsuario);
|
||||
let password = encriptar.generarPassword();
|
||||
const idUsuario = await validar.validarId(body.idUsuario);
|
||||
const password = encriptar.generarPassword();
|
||||
let correo = {};
|
||||
|
||||
return Usuario.findOne({ where: { idUsuario } })
|
||||
.then((res) => {
|
||||
if (!res) throw new Error('No existe este Usuario.');
|
||||
if (res.idTipoUsuario != 2)
|
||||
throw new Error('Este usuario no es de tipo alumno.');
|
||||
|
||||
let correo = correos.enviarSec(password, res.correo, res.nombre);
|
||||
|
||||
throw new Error('Este usuario no es de tipo responsable.');
|
||||
correo = correos.enviarSec(password, res.correo, res.nombre);
|
||||
return gmail(correo.subject, res.usuario, correo.msj);
|
||||
})
|
||||
.then((res) => {
|
||||
return Usuario.update(
|
||||
.then((res) =>
|
||||
Usuario.update(
|
||||
{ password: encriptar.encriptar(password) },
|
||||
{ where: { idUsuario } }
|
||||
);
|
||||
})
|
||||
)
|
||||
)
|
||||
.then((res) => {
|
||||
return {
|
||||
message: 'Se envio un correo con una contraseña nueva al responsable.',
|
||||
|
||||
@@ -4,13 +4,14 @@ const Usuario = require('../../db/tablas/Usuario');
|
||||
const TipoUsuario = require('../../db/tablas/TipoUsuario');
|
||||
|
||||
const responsable = async (body) => {
|
||||
let pagina = validar.validarId(body.pagina);
|
||||
let nombre = body.nombre
|
||||
const pagina = validar.validarId(body.pagina);
|
||||
const nombre = body.nombre
|
||||
? validar.validarTexto(body.nombre, 'El nombre', 60)
|
||||
: '';
|
||||
let correo = body.correo
|
||||
const correo = body.correo
|
||||
? validar.validar(body.correo, 'El correo', 1000)
|
||||
: '';
|
||||
const data = [];
|
||||
|
||||
return Usuario.findAll({
|
||||
where: {
|
||||
@@ -20,19 +21,11 @@ const responsable = async (body) => {
|
||||
},
|
||||
include: [{ model: TipoUsuario }],
|
||||
}).then((res) => {
|
||||
let data = [];
|
||||
|
||||
for (let i = pagina * 25 - 25; i < res.length && i < pagina * 25; i++)
|
||||
data.push({
|
||||
idUsuario: res[i].idUsuario,
|
||||
usuario: res[i].usuario,
|
||||
nombre: res[i].nombre,
|
||||
activo: res[i].activo,
|
||||
TipoUsuario: {
|
||||
idTipoUsuario: res[i].TipoUsuario.idTipoUsuario,
|
||||
tipoUsuario: res[i].TipoUsuario.tipoUsuario,
|
||||
},
|
||||
});
|
||||
for (let i = pagina * 25 - 25; i < res.length && i < pagina * 25; i++) {
|
||||
delete res[i].dataValues.password;
|
||||
delete res[i].dataValues.idTipoUsuario;
|
||||
data.push(res[i]);
|
||||
}
|
||||
return {
|
||||
registros: res.length,
|
||||
faltantes: res.length - data.length - (pagina - 1) * 25,
|
||||
|
||||
@@ -3,8 +3,8 @@ const validar = require('../../helper/validar');
|
||||
const Usuario = require('../../db/tablas/Usuario');
|
||||
|
||||
const responsableUpdate = async (body) => {
|
||||
let idUsuario = validar.validarId(body.idUsuario);
|
||||
let dataUpdate = {};
|
||||
const idUsuario = validar.validarId(body.idUsuario);
|
||||
const dataUpdate = {};
|
||||
|
||||
return Usuario.findOne({ where: { idUsuario } })
|
||||
.then(async (res) => {
|
||||
|
||||
Reference in New Issue
Block a user