Skip to content

Commit 6523c8a

Browse files
committed
edit porduct with value on field
1 parent 705307f commit 6523c8a

File tree

2 files changed

+18
-10
lines changed

2 files changed

+18
-10
lines changed

src/Api/routes/route.js

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,6 @@ const appRouter = async function(app, connection) {
133133
});
134134
});
135135

136-
// must add middleware for jwt allow acces
137136
// POST /products/ ⇒ Will add a product in the Products table (only if the user who create the product has a good JWT...)
138137
await app.post("/products/", auth, function(req, res) {
139138
let category = req.body.category;
@@ -207,15 +206,7 @@ const appRouter = async function(app, connection) {
207206
}
208207
})
209208

210-
// await app.post("/productEdit/:id", auth, (req, res) => {
211-
// let sql = `UPDATE products SET category = '${req.body.category}', name = '${req.body.name}', description = '${req.body.description}', prices = '${req.body.price}',url = '${req.body.url}' WHERE id = ${req.params.id}`;
212-
// connection.query(sql, (err) => {
213-
// if (err) {
214-
// console.log(err);
215-
// res.sendStatus(500);
216-
// } else res.send("Updated");
217-
// });
218-
// });
209+
219210

220211
await app.post("/userEdit/:id", auth, (req, res) => {
221212
if (typeof JSON.parse(req.params.id) === "number") {

src/Components/EditProduct.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,23 @@ class CreateProductPage extends Component {
3030
this.buttonIsClick = this.buttonIsClick.bind(this);
3131
}
3232

33+
componentDidMount() {
34+
axios.get(`http://localhost:8080/products/${localStorage.getItem("productIdToEdit")}`)
35+
.then((result) => {
36+
this.setState({
37+
category: result.data[0].category,
38+
name: result.data[0].name,
39+
description: result.data[0].description,
40+
url: result.data[0].url,
41+
prices: result.data[0].prices,
42+
id_user_affiliate: result.data[0].id_user_affiliate,
43+
});
44+
})
45+
.catch(() => {
46+
console.log("Oops, request failed!");
47+
});
48+
}
49+
3350
handleCategory(event) {
3451
this.setState({
3552
category: event.target.value,

0 commit comments

Comments
 (0)