diff --git a/db/connect.js b/db/connect.js index 63cbea6..d0c8ea3 100644 --- a/db/connect.js +++ b/db/connect.js @@ -1,12 +1,12 @@ const mysql = require('mysql'); const config = require('../config'); -var con = mysql.createConnection({ - host: "test-db.verdnatura.es", - database: "vn", - user: config.userDev, - password: config.passwordDev, - port: 3307 +let con = mysql.createConnection({ + host: 'test-db.verdnatura.es', + database: 'vn', + user: config.userDev, + password: config.passwordDev, + port: 3307 }); -exports.con = con; \ No newline at end of file +exports.con = con; diff --git a/db/create.js b/db/create.js index 1c87e0b..2bcc788 100644 --- a/db/create.js +++ b/db/create.js @@ -1,11 +1,11 @@ -const con = require('./connect.js') +const con = require('./connect.js'); con.con.connect(function(err) { if (err) throw err; - console.log("Connected!"); - var sql = "CREATE TABLE smartTag2 (code VARCHAR(100) PRIMARY KEY, shelvingFk VARCHAR(10) FOREIGN KEY REFERENCES vn.shelving(code), level INT(11))"; - con.con.query(sql, function (err, result) { - if (err) throw err; - console.log("Table created"); + console.log('Connected!'); + let sql = 'CREATE TABLE smartTag2 (code VARCHAR(100) PRIMARY KEY, shelvingFk VARCHAR(10) FOREIGN KEY REFERENCES vn.shelving(code), level INT(11))'; + con.con.query(sql, function(err, result) { + if (err) throw err; + console.log('Table created'); }); -}); \ No newline at end of file +}); diff --git a/db/insertDB.js b/db/insertDB.js index 13844e2..88a6c5d 100644 --- a/db/insertDB.js +++ b/db/insertDB.js @@ -1,10 +1,10 @@ -const con = require('./connect') +const con = require('./connect'); -function insertDB(barcode, shelving, level){ - con.con.connect(function(err) { - if (err) throw err; - //console.log("Connected!"); - var sql = `IF EXISTS(SELECT * FROM vn.smartTag WHERE code='${barcode}') +function insertDB(barcode, shelving, level) { + con.con.connect(function(err) { + if (err) throw err; + // console.log("Connected!"); + let sql = `IF EXISTS(SELECT * FROM vn.smartTag WHERE code='${barcode}') THEN UPDATE vn.smartTag SET shelvingFk = '${shelving}', level = ${level} @@ -14,10 +14,10 @@ function insertDB(barcode, shelving, level){ INTO vn.smartTag (code, shelvingFk, level) VALUES ('${barcode}', '${shelving}', ${level}); END IF;`; - con.con.query(sql, function (err, result) { - if (err) throw err; - //console.log("1 record inserted"); - }); + con.con.query(sql, function(err, result) { + if (err) throw err; + // console.log("1 record inserted"); + }); }); } -exports.insertDB = insertDB; \ No newline at end of file +exports.insertDB = insertDB; diff --git a/db/maxWagon.js b/db/maxWagon.js index 3eb84a0..f6bb291 100644 --- a/db/maxWagon.js +++ b/db/maxWagon.js @@ -1,14 +1,13 @@ -const con = require('./connect') - -function maxWagon(collectionFk, callback){ +const con = require('./connect'); +function maxWagon(collectionFk, callback) { let consSql = `SELECT MAX(tc.wagon) FROM ticketCollection tc WHERE tc.collectionFk = ${collectionFk}`; - con.con.query(consSql, function (err, result, fields) { + con.con.query(consSql, function(err, result, fields) { console.log(result); - callback(null,result); + callback(null, result); }); } -exports.maxWagon = maxWagon; \ No newline at end of file +exports.maxWagon = maxWagon; diff --git a/db/populateDb.js b/db/populateDb.js index ac8c983..fb9de95 100644 --- a/db/populateDb.js +++ b/db/populateDb.js @@ -1,9 +1,9 @@ -const con = require('./connect') +const con = require('./connect'); con.con.connect(function(err) { if (err) throw err; - console.log("Connected!"); - var sql = `INSERT INTO vn.smartTag (code, shelvingFk, level) VALUES + console.log('Connected!'); + let sql = `INSERT INTO vn.smartTag (code, shelvingFk, level) VALUES ('A0A3B8288AB1', 'ABC', 1), ('A0A3B8288AB2', 'ABC', 2), ('A0A3B8288AB3', 'ABC', 3), @@ -13,8 +13,8 @@ con.con.connect(function(err) { ('A0A3B8299CD3', 'DEF', 3), ('A0A3B8299CD4', 'DEF', 4) ;`; - con.con.query(sql, function (err, result) { - if (err) throw err; - console.log("records inserted"); + con.con.query(sql, function(err, result) { + if (err) throw err; + console.log('records inserted'); }); -}); \ No newline at end of file +}); diff --git a/db/selectDB.js b/db/selectDB.js index 386ddbd..54728b6 100644 --- a/db/selectDB.js +++ b/db/selectDB.js @@ -1,7 +1,6 @@ -const con = require('./connect') +const con = require('./connect'); - -function select(collectionFk, callback){ +function select(collectionFk, callback) { let consSql = `SELECT t.id AS Ticket, c.name AS Client, am.name AS Agency, tc.level AS Level, tc.wagon AS Wagon FROM ticketCollection tc JOIN ticket t ON t.id = tc.ticketFk JOIN client c ON t.clientFk = c.id @@ -9,13 +8,11 @@ function select(collectionFk, callback){ WHERE tc.collectionFk = ${collectionFk} ORDER BY tc.wagon, tc.level`; - con.con.query(consSql, function (err, result, fields) { + con.con.query(consSql, function(err, result, fields) { console.log(result); - callback(null,result); + callback(null, result); }); } -exports.select =select; - - +exports.select = select;