diff --git a/server/controller/Programa/get.js b/server/controller/Programa/get.js index 0d218bb..1cd34ce 100644 --- a/server/controller/Programa/get.js +++ b/server/controller/Programa/get.js @@ -1,4 +1,3 @@ -const { Op } = require('sequelize'); const validar = require('../../helper/validar'); const Programa = require('../../db/tablas/Programa'); const Usuario = require('../../db/tablas/Usuario'); @@ -7,12 +6,12 @@ const get = async (body) => { let idUsuario = validar.validarId(body.idUsuario); return Usuario.findOne({ - where: { [Op.and]: [{ idUsuario }, { idTipoUsuario: 2 }] }, + where: { idUsuario, idTipoUsuario: 2 }, }) .then((res) => { if (!res) throw new Error('Id de responsable no valido'); return Programa.findAll({ - where: { [Op.and]: [{ idUsuario }, { activo: true }] }, + where: { idUsuario, activo: true }, }); }) .then((res) => { diff --git a/server/controller/Servicio/get.js b/server/controller/Servicio/get.js new file mode 100644 index 0000000..e69de29 diff --git a/server/controller/Servicio/nuevo.js b/server/controller/Servicio/nuevo.js index 8c2ab5a..669f9b7 100644 --- a/server/controller/Servicio/nuevo.js +++ b/server/controller/Servicio/nuevo.js @@ -6,7 +6,6 @@ const Carrera = require('../../db/tablas/Carrera'); const validar = require('../../helper/validar'); const nuevo = async (body) => { - console.log('hola'); let idUsuario = validar.validarId(body.idUsuario); let idPrograma = validar.validarId(body.idPrograma); let idCarrera = validar.validarId(body.idCarrera); @@ -19,7 +18,7 @@ const nuevo = async (body) => { let cartaAceptacion = ''; return Usuario.findOne({ - where: { [Op.and]: [{ idUsuario }, { idTipoUsuario: 3 }] }, + where: { idUsuario, idTipoUsuario: 3 }, }) .then((res) => { if (!res) throw new Error('Este alumno no existe en la db.'); @@ -32,7 +31,7 @@ const nuevo = async (body) => { .then((res) => { if (!res) throw new Error('Esta carrera no existe en la db.'); return Servicio.findOne({ - where: { [Op.and]: [{ idUsuario }, { idStatus: { [Op.ne]: 10 } }] }, + where: { idUsuario, idStatus: { [Op.ne]: 10 } }, }); }) .then((res) => { diff --git a/server/controller/Servicio/serviciosAdmin.js b/server/controller/Servicio/serviciosAdmin.js index 70ec917..cb30812 100644 --- a/server/controller/Servicio/serviciosAdmin.js +++ b/server/controller/Servicio/serviciosAdmin.js @@ -1,3 +1,4 @@ +const { Op } = require('sequelize'); const validar = require('../../helper/validar'); const Servicio = require('../../db/tablas/Servicio'); const Usuario = require('../../db/tablas/Usuario'); @@ -7,13 +8,24 @@ const TipoUsuario = require('../../db/tablas/TipoUsuario'); const serviciosAdmin = async (body) => { let pagina = body.pagina; - let nombre = body.nombre; - let numeroCuenta = body.numeroCuenta; - let idStatus = body.idStatus; + let idStatus = body.idStatus ? validar.validarId(body.idStatus) : null; + let nombre = body.nombre + ? validar.validarTexto(body.nombre, 'El nombre') + : ''; + let numeroCuenta = body.numeroCuenta + ? validar.validarNumeroCuenta(body.numeroCuenta) + : ''; + let where = { nombre: { [Op.like]: `%${nombre}%` } }; + if (idStatus) where.idStatus = idStatus; return Servicio.findAll({ + where, include: [ - { model: Usuario, include: { model: TipoUsuario } }, + { + model: Usuario, + include: { model: TipoUsuario }, + where: { usuario: { [Op.like]: `%${numeroCuenta}%` } }, + }, { model: Carrera }, { model: Status }, ], diff --git a/server/controller/Servicio/serviciosResponsable.js b/server/controller/Servicio/serviciosResponsable.js new file mode 100644 index 0000000..e69de29 diff --git a/server/helper/validar.js b/server/helper/validar.js index 21cfb3b..e922f41 100644 --- a/server/helper/validar.js +++ b/server/helper/validar.js @@ -87,5 +87,3 @@ module.exports = { validarNumero, }; -// console.log(moment('2020-01-01').format()); -// 2020-01-01T00:00:00-06:00 diff --git a/server/routes/Servicio.js b/server/routes/Servicio.js index 34b9119..6311948 100644 --- a/server/routes/Servicio.js +++ b/server/routes/Servicio.js @@ -17,7 +17,6 @@ app.post(`${route}/nuevo`, (req, res) => { app.get(`${route}/servicios_admin`, (req, res) => { return serviciosAdmin(req.query) .then((data) => { - console.log(data) res.status(200).json(data); }) .catch((err) => {