How to create triggers in Firebase functions

Asked

Viewed 46 times

0

I’m working on an application that needs to receive a notification whenever a client opens a request, but I’m not able to create a Rigger so that whenever a new document is opened Firebase will run this function and notify me. What I tried to do was this:

const functions = require('firebase-functions');
const admin = require('firebase-admin');
admin.initializeApp();

exports.onNewClient = functions.firestore.document("solicitacoes/{UserId}")
    .onCreate((snap,context) => {
        console.log(snap.data());
    })

exports.getCreateEvent = functions.https.onRequest((request, response) =>{
    admin.firestore().doc("solicitacoes/{userId}").get()
    .then(snapshot =>{
        const data = snapshot.data();
        response.send(data)
    })
    .catch(error => {
        console.log(error)
        response.status(500).send(error)
    })
});

The idea is to try to create a way where the back-end is self-sufficient in running these triggers and doesn’t need an app event to let me know that a new document has been created.

1 answer

0


Browser other questions tagged

You are not signed in. Login or sign up in order to post.