-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
52 lines (42 loc) · 1.27 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
const redis = require('redis')
const express = require('express');
const app = express();
const port = 3001
const connect = require('./Connection')
const bodyParser = require('body-parser')
const jsonParser = bodyParser.json()
app.get('/basket/getBasket/:uuid', (req, res) => {
connect.createConnection().then(client => {
client.hgetall(req.params.uuid, (err, results) => {
if(results){
res.json({basket:JSON.parse(results.basket)})
}else{
res.send(err)
}
})
client.quit((err, reply) => {
if(!err){
console.log(reply)
}else{
console.log(err)
}
})
})
});
app.post('/basket/addItem',jsonParser, (req, res) => {
connect.createConnection().then(client => {
const basket = JSON.stringify(req.body.basket)
const uuid = req.body.uuid
client.hset(uuid, "basket", basket, redis.print)
client.hgetall(uuid, (err, results) => {
if(results){
res.send(results)
}else{
res.send(err)
}
})
})
})
app.listen(port, () => {
console.log('Example app listening on port!');
});