Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- componentDidMount() {
- this.callApi("Accessories")
- .then(res => {
- this.setState({
- productAccessories: this.snapshotToArray(res.data),
- }, () => {
- this.setState({
- productAccessories: this.addCategory("category", "Accessories", "productAccessories")
- }, () => {
- this.setState({
- products: this.state.productMen.concat(this.state.productKid, this.state.productWomen, this.state.productAccessories),
- }, () => {
- this.setState({
- productsToPush: this.filterProducts()
- },()=>{
- this.push()
- })
- });
- })
- })
- })
- .catch(err => {
- console.log(err);
- })
- }
- push() {
- var d = new Date();
- var today = d.getDate() + "/" + d.getMonth() + "/" + d.getFullYear()
- var updateData = {
- top4: this.state.productsToPush,
- date: today
- }
- console.log(this.state.productsToPush);
- this.postApi('/api/post/top', updateData)
- .then(res => {
- //console.log(res.data);
- })
- console.log('pushing really hard bro')
- }
- app.post('/api/post/top',(req,res) =>{
- console.log("top4 works")
- var ref=db.ref('/Top')
- ref.push(req.body.data)
- console.log("top 4 really does works")
- })
- callApi = async (category) => {
- const response = await fetch('/api/get/products/' + category);
- const body = await response.json();
- if (response.status !== 200) throw Error(body.message);
- return body;
- };
Add Comment
Please, Sign In to add comment