Diego P
Diego P

Reputation: 1758

Firebase cloud function error pushing

I have started a new project and having a push error in my function. I am not sure where the error is coming from

exports.ObserveStatus = functions.database.ref("/patients/{patient_id}/status/current").onWrite((event) => {
  const snap = event.data;
  const patient_id =  event.params.patient_id;
  if (snap.exists() && snap.child("status_id").changed()) {
    let p_timer = {
      status_id: snap.previous.child("status_id"),
      started: snap.previous.child("started"),
      ended: admin.database.ServerValue.TIMESTAMP
    };
    return admin.database().ref(`/patients/${patient_id}/status/previous`).push(p_timer);
  }

This is the error I am getting in the console:

Error: Firebase.push failed: first argument contains a function in property 'patients.-KpZ9wyqIrlTafE1sIHL.status.previous.status_id.app.firebaseInternals_.firebase_.credential.cert' with contents: function (serviceAccountPathOrObject) { var stringifiedServiceAccount = JSON.stringify(serviceAccountPathOrObject); if (!(stringifiedServiceAccount in globalCertCreds)) { globalCertCreds[stringifiedServiceAccount] = new credential_1.CertCredential(serviceAccountPathOrObject); } return globalCertCreds[stringifiedServiceAccount]; } at Error (native)

Upvotes: 0

Views: 138

Answers (1)

Diego P
Diego P

Reputation: 1758

It is missing when getting references snap.previous.child

.val()

It should be

snap.previous.child("started").val()

Upvotes: 2

Related Questions