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

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

@Maphila

Description

@Maphila

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
    */

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions