-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
83 lines (71 loc) · 2.29 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
const express = require("express");
const app = express();
//const nodemon = require("nodemon");
const mysql = require("mysql");
//app.use(nodemon);
const mysqlconnection = mysql.createConnection({
host: 'localhost',
user: "root",
database: "eventi_test",
password: ""
});
mysqlconnection.connect((err) => {
if (!err)
console.log("Db fggv ");
else
console.log(err);
})
app.listen(3000, '127.0.0.1', () => {
console.log("wowo")
})
app.get("/events", (req, res) => {
mysqlconnection.query("SELECT nome_eve,data_inizio,data_fine,vie.nome_via FROM evento as eve JOIN elenco_vie as vie ON eve.cod = vie.cod_eve ",
(err, rows, fields) => {
console.log(rows, fields)
res.json(rows)
})
})
app.get("/spazi", (req, res) => {
mysqlconnection.query("SELECT * FROM dati_spazio",
(err, rows, fields) => {
console.log(rows, fields)
res.json(rows)
})
})
app.post("/dati_spazio/:stato_spazio/:cod_spazio", (req, res) => {
var stato_spazio = req.params.stato_spazio
var cod_spazio = req.params.cod_spazio
mysqlconnection.query('UPDATE `dati_spazio` SET `stato_spazio` =' + stato_spazio + "WHERE `dati_spazio`.`cod` ' =" + cod_spazio,
(err, rows, fields) => {
console.log(rows, cfields)
res.json(rows)
}
)
})
app.get("/users/:username/:password", (req, res) => {
var uname = req.params['username']
var pwd = req.params['password']
console.log(uname)
mysqlconnection.query("INSERT INTO USERS(username, password) VALUES ('" + uname + "','" + pwd + "')",
(err, rows, fields) => {
if (err) console.log(err)
console.log(rows, fields)
res.json(fields)
})
res.json(res.data)
})
app.get("/users/:id", (req, res) => {
var id = req.params.id;
mysqlconnection.
query("SELECT * FROM USERS WHERE id='" + id + "'", (err, rows, fields) => {
if (err)
res.status(404).send({ error: err })
if (rows.length == 0) {
console.log('soccazzi', rows.length)
res.status(205).send({ error: 'no data' })
} else {
console.log('8888888', rows.length)
res.json(rows)
}
});
})