-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbackend.js
69 lines (55 loc) · 1.37 KB
/
backend.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
const express = require("express");
const app = express();
const user = [{
name:"Jhon",
kidneys :[{
healthy:true
}]
}];
app.use(express.json())
app.get("/",function(req,res){
const jhonkidneys = user[0].kidneys;
const numberofkidney = jhonkidneys.length;
let numberofhealthykidneys = 0;
for (let i = 0 ; i < jhonkidneys;i++){
if(jhonkidneys[i].healthy){
numberofhealthykidneys += 1;
}
}
const numberofunhealthykidney = numberofkidney - numberofhealthykidneys;
res.json({
numberofkidney,
numberofhealthykidneys,
numberofunhealthykidney
})
console.log(jhonkidneys);
})
app.post("/",function(req,res){
const ishealthy = req.body.ishealthy;
user[0].kidneys.push({
healthy:ishealthy
})
res.json({
msg:"Done!"
})
})
app.put("/",function(req,res){
for(let i= 0; i<user[0].kidneys.length;i++){
users[0].kidneys[i].healthy = true;
}
res.json({});
})
app.delete("/",function(req,res){
const newkideneys = [];
for (let i = 0;i<user[0].kidneys.length;i++){
if(user[0].kidneys[i].healthy){
newkideneys.push[{
healthy:true
}]
}
}
user[0].kidneys = newkideneys;
res.json({msg:"done"})
})
app.listen(3000);
//TODO server can be build using POST GET DELETE