-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
100 lines (71 loc) · 1.88 KB
/
server.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
84
85
86
87
88
89
90
91
92
93
94
95
const express = require('express')
const mongoose = require('mongoose')
const data = require('./docSchema')
var app = express()
var Data = require('./docSchema')
mongoose.connect("mongodb://localhost/newDDB")
mongoose.connection.once("open", () => {
console.log("Connected to database!")
}).on("error", (error) => {
console.log("failed to connect! " + error)
})
// CEATE NOTE
// POST request
app.post("/create", (req, res) => {
var note = new Data({
issue: req.get("issue"),
date: req.get("date"),
doctor: req.get("doctor"),
medicine: req.get("medicine"),
blood: req.get("blood"),
})
note.save().then(() => {
if(note.isNew == false){
console.log("Saved Data!")
res.send("Saved data!")
}else{
console.log("Failed to save data!")
}
})
})
// FETCH NOTE
// GET request
app.get('/fetch', (req, res) => {
Data.find({}).then((DBitems) => {
res.send(DBitems)
})
})
// DELETE NOTE
// POST request
app.post("/delete", (req, res) => {
data.findByIdAndRemove({
_id: req.get("id")
}, (err) => {
console.log("Failed " + err)
})
res.send("Deleted!")
})
// UPDATE NOTE
// POST request
app.post('/update', (req,res) => {
Data.findOneAndUpdate({
_id: req.get("id")
},{
issue: req.get("note"),
date: req.get("date"),
blood: req.get("blood"),
// weight: req.get("weight"),
// height: req.get("height"),
// heartDiseases: req.get("heartDiseases"),
doctor: req.get("doctor"),
medicine: req.get("medicine"),
//hospital: req.get("hospital"),
}, (err) => {
console.log("Failed to update " +err)
})
res.send("Updated!")
})
//http://192.168.0.7:8081/create
var server = app.listen(8082, "192.168.0.7", () => {
console.log("Server is Running!")
})