Skip to content

Commit 95ea1c4

Browse files
committedFeb 26, 2022
admin page completed
1 parent 7317814 commit 95ea1c4

File tree

2 files changed

+41
-10
lines changed

2 files changed

+41
-10
lines changed
 

‎admin.html

+2-2
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
<body>
3838
<div id="main">
3939
<div id="put">
40-
<h2>Add products</h2>
40+
<h2>Add products to Mens Database</h2>
4141
<input type="number" id="id" placeholder="Enter ID"><br>
4242
<input type="text" name="" id="title" placeholder="Enter Title"><br>
4343
<input type="text" name="" id="subtitle" placeholder="Enter Subtitle"><br>
@@ -65,7 +65,7 @@ <h2>Add products</h2>
6565
</div>
6666
<div id="delete">
6767
<h2>Delete products</h2>
68-
<input type="text" id="Delete_id" placeholder="Enter Id of the product that need to be deleted">
68+
<input type="text" id="Delete_id" placeholder="Enter Mongo Id of the product that need to be deleted">
6969
<button id="DeleteProductSubmit">Delete Product</button>
7070
</div>
7171
</div>

‎scripts/admin.js

+39-8
Original file line numberDiff line numberDiff line change
@@ -35,17 +35,40 @@ async function AddProduct(){
3535
}
3636
data = JSON.stringify(data)
3737
// console.log('data:', data)
38-
let res = await fetch('http://127.0.0.1:5555/api/productsMens',{
38+
39+
let Got_Login_Token = JSON.parse(localStorage.getItem('User_LOGIN_token'))
40+
console.log('Got_Login_Token:', Got_Login_Token)
41+
42+
43+
let res = await fetch('http://localhost:7000/catogory/mensClothing',{
3944

4045
method:'POST',
4146
body:data,
4247
headers:{
43-
'Content-Type':'application/json'
48+
'Content-Type':'application/json',
49+
'Authorization': 'Bearer ' + Got_Login_Token,
4450
}
4551
})
52+
// let res = await fetch('http://127.0.0.1:5555/api/productsMens',{
53+
54+
// method:'POST',
55+
// body:data,
56+
// headers:{
57+
// 'Content-Type':'application/json'
58+
// }
59+
// })
4660

4761
let response = await res.json()
4862
console.log('response:', response)
63+
64+
if(response.message==="authorization token was not provided or was not valid"){
65+
alert("You are not Logged In (Logged In Token required)")
66+
return
67+
}
68+
else{
69+
alert('Product Successfully Added')
70+
}
71+
4972
}
5073
catch(error){
5174
console.log('error:', "error in Addproduct function");
@@ -54,31 +77,39 @@ async function AddProduct(){
5477
}
5578
// --------------------------------------------------------------------------------------------------
5679

57-
// document.getElementById('DeleteProductSubmit').addEventListener('click',DeleteProduct)
80+
document.getElementById('DeleteProductSubmit').addEventListener('click',DeleteProduct)
5881

5982
async function DeleteProduct(){
60-
83+
console.log("here");
6184
try{
62-
let Delete_id = document.getElementById('Delete_id').value;
85+
var Delete_id = document.getElementById('Delete_id').value;
86+
console.log('Delete_id:', Delete_id)
6387
if(Delete_id === ""){
6488
alert('Enter valid id of product to be deleted');
6589
return;
6690
}
6791
console.log('Delete_id:', Delete_id);
6892

69-
let res = await fetch(`http://127.0.0.1:5555/api/productsMens/${Delete_id}`,{
93+
let res = await fetch(`http://localhost:7000/catogory/mensClothing/${Delete_id}`,{
7094
method:"DELETE",
7195
headers:{
72-
'Content-Type':'application/json'
96+
'Content-Type':'application/json',
7397
}
7498
})
7599

76100
let response = await res.json()
77101
console.log('response:', response)
102+
103+
if(response.message){
104+
alert('Enter a valid Mongo Id of product')
105+
return
106+
}
107+
108+
alert('PRoduct successfully deleted')
78109
}
79110
catch(error){
80111
console.log('error:', "error in the DeleteProduct function")
81-
112+
// alert('Enter a valid Mongo Id of product')
82113
}
83114

84115
}

0 commit comments

Comments
 (0)
Please sign in to comment.