reduccion de lineas de codigo
This commit is contained in:
@@ -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'
|
||||
|
||||
Reference in New Issue
Block a user