-
Notifications
You must be signed in to change notification settings - Fork 0
/
proj.js
67 lines (55 loc) · 1.49 KB
/
proj.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 users =[{
name:"Vishal",
Kidneys:[{
healthy: false
}],
}];
app.use(express.json());
app.get('/',(req,res)=>{
const userName = users[0].name;
const userKidneys = users[0].Kidneys;
const numberOfKidneys = userKidneys.length;
const healthyKidneys = userKidneys.filter(kidney => kidney.healthy);
const unhealthyKidneys = userKidneys.filter(kidney => !kidney.healthy);
let numberOfHealthyKidneys = healthyKidneys.length;
let numberOfUnHealthyKidneys = unhealthyKidneys.length;
resizeBy.json({
username,
numberOfKidneys,
numberOfHealthyKidneys,
numberOfUnHealthyKidneys
})
})
app.post('/',(req,res) => {
const isHealthy = req.body.isHealthy;
users[0].Kidneys.push({
healthy: isHealthy
})
res.json({
msg:"Done and healthy"
})
})
app.put('/',(req,res) => {
for(let i =0 ; i < users[0].kidney.length;i++){
users[0].kidney[i].healthy = true;
}
res.json({
msg: "now every kidney is healthy"
})
})
app.delete('/',(req,res) => {
const userKidneys = users[0].Kidneys;
users[0].Kidneys = userKidneys.filter(kidney => kidney.healthy);
if(users[0].Kidneys.length === userKidneys.length){
res.status(411).json({
msg:"you have no unhealthy kidneys"
});
}else{
res.json({
msg:"Unhealthy kidney(s0 deleted"
});
}
});
app.listen(3000);