From af88f176b72340cf85b87fceed925579dd8d3022 Mon Sep 17 00:00:00 2001 From: llopis15 Date: Wed, 24 Mar 2021 11:45:57 +0100 Subject: [PATCH] maxWagons repared --- db/maxWagon.js | 2 +- methods/setCollection.js | 19 +++++++------------ 2 files changed, 8 insertions(+), 13 deletions(-) diff --git a/db/maxWagon.js b/db/maxWagon.js index 66f44cb..f5b649f 100644 --- a/db/maxWagon.js +++ b/db/maxWagon.js @@ -1,7 +1,7 @@ const con = require('./connect'); function maxWagon(collectionFk, callback) { - let consSql = `SELECT MAX(tc.wagon) + let consSql = `SELECT MAX(tc.wagon) AS MaxWagons FROM ticketCollection tc WHERE tc.collectionFk = ${collectionFk}`; con.con.query(consSql, function(err, result, fields) { diff --git a/methods/setCollection.js b/methods/setCollection.js index 32909f7..18c362e 100644 --- a/methods/setCollection.js +++ b/methods/setCollection.js @@ -1,24 +1,19 @@ const express = require('express'); const router = express.Router(); // eslint-disable-line const select = require('../db/selectDB'); -const maxWagon = require('../db/maxWagon'); router.get('/:collectionFk', async(req, res) => { + const maxWagon = require('../db/maxWagon'); // var collectionFk = '273449'; const collectionFk = req.params.collectionFk; - let maxWagon = ticketCollection(collectionFk); - res.json({ - message: 'SUCCESS', - maxWagon: maxWagon + maxWagon.maxWagon(collectionFk, function(err, max) { + let maxWagons = max[0].MaxWagons; + res.json({ + message: 'SUCCESS', + maxWagons: maxWagons + }); }); }); module.exports = router; -function ticketCollection(collectionFk) {// parametro collectionFk - select.select(collectionFk, function(err, data) { - maxWagon.maxWagon(collectionFk, function(err, max) { - return max; - }); - }); -}