From fb1f3d8258b922de8f59f545d7bff5eccded9a95 Mon Sep 17 00:00:00 2001 From: xXpuma99Xx <51341582+xXpuma99Xx@users.noreply.github.com> Date: Sun, 13 Feb 2022 12:24:43 -0600 Subject: [PATCH] carrito update listo --- server/config/mariadb.conf.js | 6 ++++-- server/controller/Carrito/update.js | 24 +++++++++++++++++++----- server/helper/helper.js | 1 - server/routes/Prestamo.js | 24 ++++++++++++++---------- 4 files changed, 37 insertions(+), 18 deletions(-) diff --git a/server/config/mariadb.conf.js b/server/config/mariadb.conf.js index 1cee575..570627e 100644 --- a/server/config/mariadb.conf.js +++ b/server/config/mariadb.conf.js @@ -1,5 +1,5 @@ -require('./config'); const mariadb = require('mariadb'); +require('./config'); const pool = mariadb.createPool({ host: process.env.ESCOLARES_HOST, @@ -39,7 +39,9 @@ const obtenerProfesor = async (numeroCuenta) => { }); return conn - .query(`SELECT * FROM dat_profesor WHERE NumTrabajador = ${numeroCuenta}`) + .query( + `SELECT * FROM ${process.env.TABLA_PROFESORES} WHERE NumTrabajador = ${numeroCuenta}` + ) .then((rows) => { conn.end(); if (rows.length === 0) return null; diff --git a/server/controller/Carrito/update.js b/server/controller/Carrito/update.js index 71d79e9..1b248b7 100644 --- a/server/controller/Carrito/update.js +++ b/server/controller/Carrito/update.js @@ -1,18 +1,32 @@ -const { validarNumeroEntero } = require('../../helper/validar'); +const validar = require('../../helper/validar'); const dbPath = '../../db/tablas'; const Carrito = require(`${dbPath}/Carrito`); +const TipoCarrito = require(`${dbPath}/TipoCarrito`); const update = async (body) => { - const idCarrito = validarNumeroEntero(body.idCarrito, 'id carrito', true); + const idCarrito = validar.validarNumeroEntero( + body.idCarrito, + 'id carrito', + true + ); + const idTipoCarrito = body.idTipoCarrito + ? validar.validarNumeroEntero(body.idTipoCarrito, 'id tipo carrito', true) + : null; let update = {}; - return Carrito.findOne({ where: { idCarrito } }) + return TipoCarrito.findOne({ where: { idTipoCarrito } }) + .then((res) => { + if (idTipoCarrito && !res) + throw new Error('No existe este tipo carrito.'); + return Carrito.findOne({ where: { idCarrito } }); + }) .then((res) => { if (!res) throw new Error('No existe este carrito.'); - // habilitar cambio de modulo u tipo de equipo + if (idTipoCarrito) update.idTipoCarrito = idTipoCarrito; if (body.activo === 'desactivar') update.activo = false; else if (body.activo === 'activar') update.activo = true; - else throw new Error('No se envio nada para actualizar.'); + if (validar.validarObjetoVacio(update)) + throw new Error('No se envio nada para actualizar.'); return Carrito.update(update, { where: { idCarrito } }); }) .then(() => ({ message: 'Se actualizó correctamente el carrito.' })); diff --git a/server/helper/helper.js b/server/helper/helper.js index 29d7948..cfa3c45 100644 --- a/server/helper/helper.js +++ b/server/helper/helper.js @@ -1,5 +1,4 @@ const fs = require('fs'); -const moment = require('moment'); const eliminarArchivo = (path) => { return new Promise((resolve, reject) => { diff --git a/server/routes/Prestamo.js b/server/routes/Prestamo.js index 6424f27..8cf5eb1 100644 --- a/server/routes/Prestamo.js +++ b/server/routes/Prestamo.js @@ -62,7 +62,7 @@ app.put(`${route}/regresar_numero_inventario`, verificaToken, (req, res) => { }); }); -app.put(`${route}/regreso_inmediato`, (req, res) => { +app.put(`${route}/regreso_inmediato`, verificaToken, (req, res) => { return regresoInmediato(req.body) .then((data) => { res.status(200).json(data); @@ -72,15 +72,19 @@ app.put(`${route}/regreso_inmediato`, (req, res) => { }); }); -app.put(`${route}/regreso_inmediato_numero_inventario`, (req, res) => { - return regresoInmediatoNumeroInventario(req.body) - .then((data) => { - res.status(200).json(data); - }) - .catch((err) => { - res.status(400).json({ message: err.message }); - }); -}); +app.put( + `${route}/regreso_inmediato_numero_inventario`, + verificaToken, + (req, res) => { + return regresoInmediatoNumeroInventario(req.body) + .then((data) => { + res.status(200).json(data); + }) + .catch((err) => { + res.status(400).json({ message: err.message }); + }); + } +); app.put(`${route}/cancelar_usuario`, verificaToken, (req, res) => { return cancelarUsuario(req.body)