Не удалось настроить провайдеры триггеров / cloud.firestore / eventTypes / document.update - PullRequest
0 голосов
/ 21 сентября 2018

Я планирую обновлять news_author_user_type каждый раз, когда происходит обновление user_type в узле пользователей

Вот мой код

exports.onUpdateUserType = functions.firestore
    .document('users/{user_id')
    .onUpdate((change, context) => {
        const newUserDoc = change.after.data();
        const user_type = newUserDoc.user_type;
        const user_id = context.auth.uid;

        const db = admin.firestore();
        const newsRef = db.collection('news').where('news_author_id', '==', user_id);
        const news =  newsRef.get().then(onSnapshot => {
            onSnapshot.forEach(result => {
                const news_id = result.id;
                const newsDoc = db.doc(`news/${news_id}`);
                const news_author_type = {
                    news_author_type:user_type
                };
                newsDoc.update(news_author_type).then(onUpdate => {
                    return onUpdate;
                }).catch(onErrorUpdate => {
                    return onErrorUpdate;
                });
            });
        });
    });

Ответы [ 2 ]

0 голосов
/ 03 мая 2019
exports.achievements = functions.firestore.document("notifications/{any}/{any}/{any}").onCreate((snap, context) => {

В моем случае я изменил "notifications/{any}/{any}/{any}" на: "notifications/{anyday}/{anytype}/{anydoc}"

0 голосов
/ 09 октября 2018

Проверьте, что триггер де-функции имеет опечатку

functions.firestore.document('users/{user_id')

Это должно быть:

functions.firestore.document('users/{user_id}')
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...