daily pastebin goal
45%
SHARE
TWEET

Untitled

a guest Jan 18th, 2019 65 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import db from '../db';
  2.  
  3. /*
  4.   Options:
  5.   - ref: Specify the ref of a document
  6.   - collectionName: Specify the collection name
  7.   - queryArgs: Specify the arguments to be passed down to .where()
  8.   - orderByArgs: Specify the arguments to be passed down to .orderBy()
  9.   - limit: Specify the fetching limit
  10.   - docName: Specify the document name/id
  11. */
  12. export default options => {
  13.   const { ref, collectionName, queryArgs, orderByArgs, limit, docName } = options;
  14.  
  15.   if (ref != null) return ref;
  16.  
  17.   const initRef = db.collection(collectionName);
  18.  
  19.   if (docName != null) return initRef.doc(docName);
  20.  
  21.   if (queryArgs != null) {
  22.     if (orderByArgs != null) {
  23.       if (limit != null)
  24.         return initRef
  25.           .where(...queryArgs)
  26.           .orderBy(...orderByArgs)
  27.           .limit(limit);
  28.       return initRef.where(...queryArgs).orderBy(...orderByArgs);
  29.     }
  30.     return initRef.where(...queryArgs);
  31.   }
  32.  
  33.   return initRef;
  34. };
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top