Reference.update fehlgeschlagen: Erstes Argument enthält eine Funktion in Eigenschaft?

Nov 20 2020

Ich erhalte die folgenden Fehler, wenn ich versuche, eine einfache Cloud-Funktion zu erstellen, die ein "Gefällt mir" auf dem RD erkennt und dann Beiträge auf einer Benutzerzeitleiste anzeigt.

Wie kann ich die Funktion reparieren? Was mache ich falsch?


(2 Fehler unten sind von der Firebase Cloud-Funktionskonsole)

onPostLike

Fehler beim Abrufen des Benutzernamens von Likern: Fehler: Reference.update fehlgeschlagen: Das erste Argument enthält eine Funktion in der Eigenschaft 'UserFYP.Bke7CYXP31dpyKdBGsiMOEov2q43.0PMdzaOyYBejf1Gh6Pk1RRA5WNJ2.postID.node_.children_.comparator_'

onPostLike

TypeError: Die Eigenschaft 'get' von undefined kann unter ServerResponse.json (/workspace/node_modules/express/lib/response.js:257:20) unter ServerResponse.send (/workspace/node_modules/express/lib/response.js) nicht gelesen werden. 158: 21) unter likerUIDRef.once.then.catch.error (/workspace/lib/index.js:669:52) unter process._tickCallback (internal / process / next_tick.js: 68: 7)

Verwandte Typoskript:

 function addPersonalizedFYPPosts(whoLikes: string, postUID: string, postID: string) {
      
      //need to use data to fetch my latest likes
      //then I use the likers data to add the new post to his fypTimeline

      const ref = admin.database().ref(`Likes/${postUID}/${postID}/media1`);
      return ref.once("value") 
      .then(snapshot => {

        //use snapshot to get the my latest like ??
        //Now with this ssnapshot we see other people who liked the same post this liker has. get one of their UIDs and see what else they liked add that to thte likers timeline. 

        var i2 = 0

        snapshot.forEach((theChild) => {

          if (i2 == 0) {

            let uid = theChild.key
          
            //do what you want with the uid
  
            //const userWhoAlsoLiked = snapshot.forEach
  
            const likerUIDRef = admin.database().ref(`YourLikes/${uid}`); likerUIDRef.once("value") .then(snap =>{ //const username = snap.val() var i = 0 snap.forEach((child) => { //UserFYP if (i == 0) { let timelineID = child.key; let timeStamp = child.child("timeStamp"); let newPostID = child.child("postID"); let postUid = child.child("uid"); //admin.database().ref(`UserFYP/${whoLikes}/${timelineID}/`).update(["":""]) admin.database().ref(`UserFYP/${whoLikes}/${timelineID}/`).set({"postID": newPostID, "uid": postUid, "timeStamp": timeStamp})
                  .then(slap =>{
                    console.log("Success updating user FYP: " )
                    return Promise.resolve();
                  })
                  .catch(error => {
                    console.log("Error fetching likers username: " + error)
                    response.status(500).send(error);
                  })
                  i++;
                }
                // return;
              })
              
            })
            .catch(error => {
              console.log("Error fetching likers username: " + error)
              response.status(500).send(error)
            })
            
            return;
            
            i2++;
          }
      })

      })
      .catch(error => {
        console.log("The read failed: " + error)
        response.status(500).send(error)
      })  

    }

export const onPostLike = functions.database
.ref('/Likes/{myUID}/{postID}/media1/{likerUID}')
.onCreate((snapshot, context) => {
  const uid = context.params.likerUID
  const postID = context.params.postID
  const myUID = context.params.myUID
  //addNewFollowToNotif(uid, followerUID)

  return addPersonalizedFYPPosts(uid,myUID,postID);
})

Antworten

1 FrankvanPuffelen Nov 20 2020 at 09:10

Der Aufruf child()auf eine DataSnapshotgibt Ihnen eine andere DataSnapshot. Damit:

  snap.forEach((child) => {
    //UserFYP
    if (i == 0) {
      let timelineID = child.key;
      let timeStamp = child.child("timeStamp");
      let newPostID = child.child("postID");
      let postUid = child.child("uid");

In diesem Code sind Ihre lokalen Variablen Snapshots, die ua Funktionen für den Zugriff auf sie enthalten. Da Sie nur JSON in die Datenbank schreiben können, werden die Snapshots abgelehnt.

Was Sie wahrscheinlich suchen, ist:

  snap.forEach((child) => {
    //UserFYP
    if (i == 0) {
      let timelineID = child.key;
      let timeStamp = child.child("timeStamp").val();
      let newPostID = child.child("postID").val();
      let postUid = child.child("uid").val();