This commit is contained in:
Victor Turgeon 2022-10-18 12:07:13 -04:00
parent fe5d00264d
commit a61c40ae79

View File

@ -21,9 +21,6 @@ const Inventaire = () => {
}, []);
const handleAddItem = async (morceau) => {
console.log(morceau);
const response = await fetch(`https://localhost:7292/api/Product`, {
method: 'POST',
headers: {
@ -33,7 +30,8 @@ const Inventaire = () => {
body: JSON.stringify(morceau)
})
const newMorceau = response.json();
const newMorceau = await response.json();
console.log(newMorceau);
if (response.ok)
setMorceaux([...morceaux, { ...newMorceau }]);
@ -45,8 +43,12 @@ const Inventaire = () => {
const response = await fetch(`https://localhost:7292/api/Product?id=${id}`, { method: 'DELETE', mode: 'cors' });
if (response.ok)
setMorceaux(morceaux.filter((morceau) => morceau.id !== id))
const deletedId = await response.json();
if (response.ok){
setMorceaux(morceaux.filter((morceau) => morceau.id !== deletedId));
console.log("DELETE de: "+deletedId +" avec succès!");
}
else
console.log("Erreur leur du DELETE de " + id);
};