Guest User

Untitled

a guest
Jan 18th, 2019
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.91 KB | None | 0 0
  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. };
Add Comment
Please, Sign In to add comment