-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
81 lines (57 loc) · 1.31 KB
/
index.js
File metadata and controls
81 lines (57 loc) · 1.31 KB
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
const express=require('express')
const app=express();
app.use(express.json())
const data=[]
app.listen(3333,()=>(console.log("server started at port no 4001")))
app.get("/",(req,res)=>{
res.send(`<h1>YOUR WELCOME</h1>`)
})
app.post('/add',(req,res)=>{
const {number,task}=req.body
data.push({number,task})
res.json({
output:data
}) })
app.get('/getalltask',(req,res)=>{
if(data.length==0){
return res.json(
{
message:"Empty todo"
}
)
}
res.send({
output:data
})
})
app.get('/specifictask/:number',(req,res)=>{
const number=req.params.number;
const output=data.filter((data)=>(number==data.number))
if(output.length==0){
res.send({
message:"Empty"
})
}
res.send(output)
})
app.patch('/updateNoOftask',(req,res)=>{
const{oldnumber,newnumber}=req.body
data.map((data)=>{
data.number==oldnumber?data.number=newnumber:data.number
})
res.send({data})
})
app.put("/changeTask",(req,res)=>{
const {oldtask,newtask}=req.body
data.map((data)=>{
data.task==oldtask?data.task=newtask:data.task
})
res.send({
data
})
})
app.delete('/deletetask',(req,res)=>{
const tasks=req.body.task
const temp= data.filter((Task)=>(Task.task!=tasks))
res.send(temp)
})