Облачная функция Firebase не работает? - PullRequest
0 голосов
/ 30 мая 2019

Я написал нижеприведенный код, чтобы определить, когда комментарий был добавлен в БД, а затем ответить обновлением узла временной шкалы, проблема в том, что он фактически не обновляется. Почему это не работает?

    export const onCommentAdded = functions.database
.ref('/Comments/{receiverUID}/{postID}/{mediaNum}/{commentID}')
.onCreate((snapshot, context) => {
  const uid = context.params.uid
  const newCommentUID = snapshot.child("UID").val()
  console.log(newCommentUID, " the comment")
  return addNewCommentNotif(uid, newCommentUID) 
})

function addNewCommentNotif(uuid: string, newCommentUID: string) {

  //NotifTimeline/uid/NewNotif (someuniqueVal)/commentID
  const randID = Math.floor(100000000 + Math.random() * 900000000);
  const notifTimelineRef = admin.database().ref("NotifTimeline").child(uuid).child(newCommentUID + ":" + randID).child("NewComment")

  notifTimelineRef.set(newCommentUID)//update
  .then(() => {
    console.log("Success updating this uid comment timeline")
  })
  .catch((error: string) => {
    console.log("Error in catch: "+error)
    response.status(500).send(error)
  })
  return Promise.resolve();
}

Ответы [ 2 ]

1 голос
/ 31 мая 2019

ToraCode понял это правильно в своем комментарии, когда сказал:

Я думаю, это из-за вашего const uid = context.params.uid.Я не вижу ни одного имени параметра в вашей ссылке

1 голос
/ 30 мая 2019

Вернуть обещание, которое было возвращено set ():

function addNewCommentNotif(uuid: string, newCommentUID: string) {

  //NotifTimeline/uid/NewNotif (someuniqueVal)/commentID
  const randID = Math.floor(100000000 + Math.random() * 900000000);
  const notifTimelineRef = admin.database().ref("NotifTimeline").child(uuid).child(newCommentUID + ":" + randID).child("NewComment")

  return notifTimelineRef.set(newCommentUID)//update
  .then(() => {
    console.log("Success updating this uid comment timeline")
  })
  .catch((error: string) => {
    console.log("Error in catch: "+error)
    response.status(500).send(error)
  })
}
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...