Untitled

 avatar
unknown
typescript
3 years ago
927 B
5
Indexable
 .https.onCall(async (data, context) => {
        let promises: Promise<any>[] = [];
        const asyncFunc = async () => {
            const reports = await firestore.collection('reports')
                .where('isDev', '==', false)
                .get()
            reports.docs.map(async doc => {
                const reportDocRef = doc.ref;
                const reportData = doc.data();
                if (reportData.userId) {
                    const user = await firestore.collection('users').doc(reportData.userId).get()
                    promises.push(
                        reportDocRef.update({ username: user.data()?.username, userEmail: user.data()?.email })
                    );
                }
            });
            const allPromises = Promise.all(promises);
            return allPromises.then(() => {
                return true;
            })
        }
        return asyncFunc();
    });