Untitled

mail@pastecode.io avatar
unknown
typescript
2 years ago
927 B
4
Indexable
Never
 .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();
    });