const getComments = async (parentId, slug, type, limit) => { const db = firebase.firestore(); let commentsQuery = db.collection('comments3') .where('postType', '==', type) .where('postId', '==', slug) .where('parentId', '==', parentId || null) .orderBy("createdAt"); if (limit) { commentsQuery = commentsQuery.limit(limit); } return commentsQuery.get();; }
deleteFavorite(id: string): Promise<void> { const db = firebase.firestore(); if (this.userId) { return db.collection('favorites').where('user', '==', this.userId).where('dish', '==', id).get() .then(doc => { doc.forEach( docu => { return db.doc('favorites/' + docu.id).delete(); }); }); } else { return Promise.reject(new Error('No User Logged In!')); } }
const fetchNextPaintings = lastVisible => async dispatch => { try { dispatch({ type: PAINTINGS_FETCH, }); const firebase = require('firebase'); // eslint-disable-line global-require require('firebase/firestore'); // eslint-disable-line global-require const db = firebase.firestore(); const snapshots = await db .collection('paintings') .orderBy('createdAt', 'desc') .startAfter(lastVisible) .limit(FETCH_LIMIT) .get(); dispatch({ type: PAINTINGS_FETCH_NEXT, payload: parseSnapshots(snapshots), lastVisible: snapshots.docs[snapshots.docs.length - 1], }); } catch (err) { console.log('err:', err); dispatch({ type: PAINTINGS_FETCH_ERROR, payload: err, }); } }
.where( "author", '==', userRef ) .orderBy( "ts_added", "desc" ) .limit( 5 ).get(); } else { snapshot = await firestore .orderBy( "ts_added", "desc" ) .startAfter( lastVisible.ts_added ) .limit( 5 ).get(); let author = { displayName: "Unknown" }; if ( fe.author ) { let res = await fe.author.get(); author = res.data(); } else {
snapshot = await firestore .collection( "blogs" ).orderBy( "ts_added", "desc" ) .limit( 5 ).get(); } else { snapshot = await firestore .collection( "blogs" ).orderBy( "ts_added", "desc" ) .startAfter( lastVisible.ts_added ) .limit( 5 ).get(); let author = { displayName: "Unknown" }; if ( fe.author ) { let res = await fe.author.get(); author = res.data(); } else {
/* postFavorites(dishids: any) { return this.http.post(baseURL + 'favorites/', dishids) .catch(error => { return this.processHTTPMsgService.handleError(error); }); } */ isFavorite(id: string): Promise<boolean> { const db = firebase.firestore(); if (this.userId) { return db.collection('favorites').where('user', '==', this.userId).where('dish', '==', id).get() .then(doc => { return !doc.empty; }); } else { return Promise.resolve(false); } }