move addUser(), deleteUser() into usersFetch.js
parent
2213e7187a
commit
ef1843a61f
@ -0,0 +1,55 @@
|
||||
|
||||
class userFetch{
|
||||
|
||||
addUser = (bodyData) => {
|
||||
console.log(bodyData);
|
||||
// setup automatic proxy in package.json.
|
||||
// thus eliminating the need to type "http://localhost:7000"
|
||||
// "proxy" : "http://localhost:7000"
|
||||
fetch(`/users`, {
|
||||
method: "POST",
|
||||
body: JSON.stringify(bodyData),
|
||||
headers: { "Content-type": "application/json; charset=UTF-8" },
|
||||
})
|
||||
.then((res) => res.text())
|
||||
.then((data) => {
|
||||
console.log(data);
|
||||
|
||||
//this.setState({ items: data });
|
||||
//console.log(this.state.user);
|
||||
|
||||
return true;
|
||||
})
|
||||
.catch((err) => {
|
||||
console.log(err);
|
||||
|
||||
return false;
|
||||
});
|
||||
}
|
||||
|
||||
deleteUser = (id) => {
|
||||
// setup automatic proxy in package.json.
|
||||
// thus eliminating the need to type "http://localhost:7000"
|
||||
// "proxy" : "http://localhost:7000"
|
||||
fetch(`/users/${id}`, {
|
||||
method: "DELETE"
|
||||
})
|
||||
.then((res) => res.json())
|
||||
.then((data) => {
|
||||
console.log(data);
|
||||
//alert(`Deleted user ${id}`);
|
||||
//this.setState({ items: data });
|
||||
//console.log(this.state.user);
|
||||
return true;
|
||||
})
|
||||
.catch((err) => {
|
||||
console.log(err);
|
||||
alert(`Fail to delete user ${id}`);
|
||||
return false;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
const apiFetch = new userFetch();
|
||||
|
||||
export default apiFetch;
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 3.7 KiB |
|
Before Width: | Height: | Size: 2.6 KiB After Width: | Height: | Size: 2.6 KiB |
Loading…
Reference in New Issue