Skip to content
This repository has been archived by the owner on Oct 17, 2019. It is now read-only.

Deleting Child in raw-bus-location after 10 seconds #58

Open
Maphila opened this issue Nov 30, 2018 · 2 comments
Open

Deleting Child in raw-bus-location after 10 seconds #58

Maphila opened this issue Nov 30, 2018 · 2 comments

Comments

@Maphila
Copy link

Maphila commented Nov 30, 2018

I'm trying to delete child (Trip) in raw-bus location (Firebase) after 10 seconds. But getting errors in code, still learning node js. Any help is much appreciated.

exports.DeleteChild = class {
constructor(timeRef, rawBusLocationsRef, cutoff, oldItemsQuery ){
this.timeRef = timeRef;
this.rawBusLocationsRef = rawBusLocationsRef;
this.cutoff = cutoff;
this.oldItemsQuery = oldItemsQuery;

// Change the panel once every ten seconds
this.timeTimerId = setInterval(() => {
  this.deleteChild();
}, 10000);

}

deleteChild(){
this.cutoff = this.timeRef - 10000;
this.oldItemsQuery = this.rawBusLocationsRef.orderByChild('timestamp').endAt(this.cutoff);
return this.oldItemsQuery.once('value').then((snapshot) => {
// create a map with all children that need to be removed
const updates = {};
snapshot.forEach(child => {updates[child.key] = null;});
// execute all updates in one go and return the result to end the function
return this.rawBusLocationsRef.update(updates);
});
}};

and the error is:

/*

  • Error: Query.endAt failed: first argument contains NaN in property 'raw-bus-location'
    at validateFirebaseData (/home/maphilak/server4r/node_modules/@firebase/database/dist/index.nod
    e.cjs.js:1443:15)
    at validateFirebaseDataArg (/home/maphilak/server4r/node_modules/@firebase/database/dist/index.
    node.cjs.js:1421:5)
    at Query.endAt (/home/maphilak/server4r/node_modules/@firebase/database/dist/index.node.cjs.js:
    4985:9)
    at exports.DeleteChild.deleteChild (/home/maphilak/server4r/delete_child.js:23:74)
    at Timeout.timeTimerId.setInterval [as _onTimeout] (/home/maphilak/server4r/delete_child.js:16:
  1. at ontimeout (timers.js:475:11)
    at tryOnTimeout (timers.js:310:5)
    at Timer.listOnTimeout (timers.js:270:5)
    npm ERR! code ELIFECYCLE
    npm ERR! errno 1
    npm ERR! transport-tracker-server@1.0.0 main: node main.js
    npm ERR! Exit status 1
    npm ERR!
    npm ERR! Failed at the transport-tracker-server@1.0.0 main script.
    npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
    npm ERR! A complete log of this run can be found in:
    npm ERR! /home/maphilak/.npm/_logs/2018-11-30T10_50_04_443Z-debug.log
    */
@stale
Copy link

stale bot commented Oct 3, 2019

This issue has been automatically marked as stale because it has not had recent activity. Please comment here if it is still valid so that we can reprioritize. Thank you!

@stale stale bot added the stale label Oct 3, 2019
@Maphila
Copy link
Author

Maphila commented Oct 4, 2019 via email

@stale stale bot removed the stale label Oct 4, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant