Guest User

Untitled

a guest
Jul 18th, 2018
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.68 KB | None | 0 0
  1. componentDidMount() {
  2. this.callApi("Accessories")
  3. .then(res => {
  4. this.setState({
  5. productAccessories: this.snapshotToArray(res.data),
  6.  
  7. }, () => {
  8. this.setState({
  9. productAccessories: this.addCategory("category", "Accessories", "productAccessories")
  10. }, () => {
  11. this.setState({
  12. products: this.state.productMen.concat(this.state.productKid, this.state.productWomen, this.state.productAccessories),
  13. }, () => {
  14. this.setState({
  15. productsToPush: this.filterProducts()
  16. },()=>{
  17. this.push()
  18. })
  19. });
  20. })
  21. })
  22. })
  23. .catch(err => {
  24. console.log(err);
  25. })
  26. }
  27.  
  28. push() {
  29. var d = new Date();
  30. var today = d.getDate() + "/" + d.getMonth() + "/" + d.getFullYear()
  31. var updateData = {
  32. top4: this.state.productsToPush,
  33. date: today
  34. }
  35. console.log(this.state.productsToPush);
  36. this.postApi('/api/post/top', updateData)
  37. .then(res => {
  38. //console.log(res.data);
  39. })
  40. console.log('pushing really hard bro')
  41. }
  42.  
  43. app.post('/api/post/top',(req,res) =>{
  44. console.log("top4 works")
  45. var ref=db.ref('/Top')
  46. ref.push(req.body.data)
  47. console.log("top 4 really does works")
  48. })
  49.  
  50. callApi = async (category) => {
  51.  
  52. const response = await fetch('/api/get/products/' + category);
  53. const body = await response.json();
  54.  
  55. if (response.status !== 200) throw Error(body.message);
  56.  
  57. return body;
  58. };
Add Comment
Please, Sign In to add comment