-
Notifications
You must be signed in to change notification settings - Fork 2
/
admin.js
93 lines (71 loc) · 2.1 KB
/
admin.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
//create data
const createData = async function (){
let id = document.getElementById("id").value;
let location = document.getElementById("locationinput").value;
let image = document.getElementById("image").value;
let name = document.getElementById("name").value;
let description = document.getElementById("description").value;
let price = document.getElementById("price").value;
let ratings = document.getElementById("ratings").value;
let send_data ={
id,
location,
image,
name,
description,
price,
ratings,
}
console.log('send_data:', send_data);
let res = await fetch(`http://localhost:3000/hotels`,{
method:"POST",
body: JSON.stringify(send_data),
headers:{
'Content-Type':'application/json'
}
});
console.log('res:', res);
let data = await res.json();
console.log('dataCreate:', data)
window.location.reload()
}
//delete data from json
const deleteData = async () => {
try{
let delete_id = document.getElementById("delete_id").value;
let res = await fetch(`http://localhost:3000/hotels/${delete_id}`,{
method:"DELETE",
headers:{
'Content-Type':'application/json'
}
});
console.log('res:', res);
let data = await res.json();
console.log('Deletedata:', data)
}
catch(err){
console.log(err)
}
}
//update data
const updateData = async() =>{
try{
let update_id = document.getElementById("update_id").value;
let update_name = document.getElementById("update_name").value;
let send_data = {
name:update_name,
}
let res = await fetch(`http://localhost:3000/hotels/${update_id}`,{
method:"PATCH",
body:JSON.stringify(send_data),
headers:{
'Content-Type':'application/json'
}
});
let data = await res.json();
console.log('Updatedata:', data)
}
catch(err){
console.log(err)
}
}