Skip to content

Commit

Permalink
Merge pull request #3 from santiPachi/master
Browse files Browse the repository at this point in the history
se imprime con el formato correcto
  • Loading branch information
huasipango committed Mar 11, 2019
2 parents 14ae927 + 3484bee commit fef29c7
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 20 deletions.
8 changes: 7 additions & 1 deletion app/node/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ app.get("/users/:id", (req,res) => {
app.post("/adduser", (req, res) => {


var subcription = JSON.stringify(req.body);
var subcription = JSON.stringify(req.body.subscription);
console.log("subs"+subcription);
if(subcription){
pool.query('INSERT INTO usuario (usu_subs) VALUES(?)', [subcription], (err, rows, fields) => {
Expand All @@ -78,6 +78,12 @@ app.post("/adduser", (req, res) => {
}
})

app.get("/api/subscriptions", (req,res) => {
const queryString = "SELECT usu_subs FROM usuario"
pool.query(queryString, (err, rows, fields) => {
res.json(rows)
})
})

app.listen(PORT, () => {
console.log(`server running on port ${PORT}`)
Expand Down
56 changes: 37 additions & 19 deletions app/scripts/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -223,25 +223,43 @@ function getUsuairio() {

function insertSubcription(subscription){
var str = JSON.stringify(subscription);
var data = JSON.parse(str);
$.ajax({
url: "http://localhost:5000/adduser/",
type: "POST",
data: data,
dataType: "json",
success: function (result) {
switch (result) {
case true:
processResponse(result);
break;
default:
resultDiv.html(result);
}
},
error: function (xhr, ajaxOptions, thrownError) {
alert(xhr.status);
alert(thrownError);
}
var subscriptionObject = JSON.parse(str);
// $.ajax({
// url: "http://localhost:5000/adduser/",
// type: "POST",
// data: data,
// dataType: "json",
// success: function (result) {
// switch (result) {
// case true:
// processResponse(result);
// break;
// default:
// resultDiv.html(result);
// }
// },
// error: function (xhr, ajaxOptions, thrownError) {
// alert(xhr.status);
// alert(thrownError);
// }
// });
fetch('http://localhost:5000/adduser/', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({
subscription: subscriptionObject

})
})
.then((response) => {
if (response.status !== 200) {
return response.text()
.then((responseText) => {
throw new Error(responseText);
});
}
});
}

0 comments on commit fef29c7

Please sign in to comment.