-
Notifications
You must be signed in to change notification settings - Fork 0
/
smart-bottle-Api.js
50 lines (46 loc) · 1.36 KB
/
smart-bottle-Api.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
const express = require('express')
const app = express()
app.use(express.static('public'))
const bodyParser = require('body-parser')
const jsonEncoder = bodyParser.json()
const dbInterface = require('./databaseInterface')
app.post('/adduser/:username/:addr', jsonEncoder, function (request, response) {
const name = request.params.username
const addr = request.params.addr
dbInterface.insertUser(name, addr)
.then((result)=>{
console.log(result)
response.send('SuccessFull')
})
.catch((err)=>{
console.log(err.original.detail)
response.sendStatus(500)
})
})
app.post('/addbottle/:bottlename/:quantity', jsonEncoder, function (request, response) {
const name = request.params.bottlename
const quantity = request.params.quantity
dbInterface.insertBottle(name, quantity)
.then((result)=>{
console.log(result)
response.send('SuccessFull')
})
.catch((err)=>{
console.log(err.original.detail)
response.sendStatus(500)
})
})
app.post('/addbottle/:bottlename/:quantity', jsonEncoder, function (request, response) {
const name = request.params.bottlename
const quantity = request.params.quantity
dbInterface.insertBottle(name, quantity)
.then((result)=>{
console.log(result)
response.send('SuccessFull')
})
.catch((err)=>{
console.log(err.original.detail)
response.sendStatus(500)
})
})
app.listen(8080)