@@ -35,17 +35,40 @@ async function AddProduct(){
35
35
}
36
36
data = JSON . stringify ( data )
37
37
// 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' , {
39
44
40
45
method :'POST' ,
41
46
body :data ,
42
47
headers :{
43
- 'Content-Type' :'application/json'
48
+ 'Content-Type' :'application/json' ,
49
+ 'Authorization' : 'Bearer ' + Got_Login_Token ,
44
50
}
45
51
} )
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
+ // })
46
60
47
61
let response = await res . json ( )
48
62
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
+
49
72
}
50
73
catch ( error ) {
51
74
console . log ( 'error:' , "error in Addproduct function" ) ;
@@ -54,31 +77,39 @@ async function AddProduct(){
54
77
}
55
78
// --------------------------------------------------------------------------------------------------
56
79
57
- // document.getElementById('DeleteProductSubmit').addEventListener('click',DeleteProduct)
80
+ document . getElementById ( 'DeleteProductSubmit' ) . addEventListener ( 'click' , DeleteProduct )
58
81
59
82
async function DeleteProduct ( ) {
60
-
83
+ console . log ( "here" ) ;
61
84
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 )
63
87
if ( Delete_id === "" ) {
64
88
alert ( 'Enter valid id of product to be deleted' ) ;
65
89
return ;
66
90
}
67
91
console . log ( 'Delete_id:' , Delete_id ) ;
68
92
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 } ` , {
70
94
method :"DELETE" ,
71
95
headers :{
72
- 'Content-Type' :'application/json'
96
+ 'Content-Type' :'application/json' ,
73
97
}
74
98
} )
75
99
76
100
let response = await res . json ( )
77
101
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' )
78
109
}
79
110
catch ( error ) {
80
111
console . log ( 'error:' , "error in the DeleteProduct function" )
81
-
112
+ // alert('Enter a valid Mongo Id of product')
82
113
}
83
114
84
115
}
0 commit comments