Created
April 5, 2016 20:15
-
-
Save fedebrasburg/5a8bf3717fc34cd4b454783937c77564 to your computer and use it in GitHub Desktop.
Creacion de intereses
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
router.post('/api/v1/tander/interes', upload.array(), function (req, res, next) { | |
var results = []; | |
// Grab data from http request | |
var data = {nombre: req.body.interest.value, categoria: req.body.interest.category}; | |
console.log(req.body); | |
// Get a Postgres client from the connection pool | |
pg.connect(connectionString, function(err, client, done) { | |
// Handle connection errors | |
if(err) { | |
done(); | |
console.log(err); | |
return res.status(500).json({ success: false, data: err}); | |
} | |
//Busco el id de la categoria | |
var id = [] | |
var consulta = client.query("Select id from categorias where nombre = '"+data.categoria+"'"); | |
consulta.on('row', function(row) { | |
data.categoria = row.id; | |
}); | |
if(data.categoria == undefined){ | |
done(); | |
return res.status(500).json({ success: false, data: "Categoria inexistente"}); | |
} | |
consulta.on('end',function(err){ | |
client.query("INSERT INTO interes (nombre,categoria) values($1,$2)", [data.nombre,data.categoria],function(err,result){ | |
return res.sendStatus(201); | |
}); | |
}); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment