daily pastebin goal
84%
SHARE
TWEET

tags.js

a guest Jan 12th, 2019 77 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. exports.getStoresByTag = async (req, res) => {
  2.   const tagQuery = req.params.tag || {
  3.     $exists: true,
  4.     $ne: [],
  5.   };
  6.  
  7.   const tagsPromise = Store.getTagsList();
  8.   const storesPromise = Store.find({
  9.     tags: tagQuery,
  10.   });
  11.   // experimental
  12.   const tagsPromiseOfIsp = Isp.getTagsList();
  13.   const ispsPromise = Isp.find({
  14.     tags: tagQuery,
  15.   });
  16.  
  17. const tagsPromiseOfEcommerce = Ecommerce.getTagsList();
  18.   const ecommercePromise = Ecommerce.find({
  19.     tags: tagQuery,
  20.   });
  21.  
  22.  
  23.   let [tags, stores, tagsOfIsp, isps, tagsOfEcommerce, ecommerces] = await Promise.all([tagsPromise, storesPromise, tagsPromiseOfIsp, ispsPromise,tagsPromiseOfEcommerce, ecommercePromise  ]);
  24.  
  25.   // tags.push(tagsOfIsp);
  26.   // stores.push(isps);
  27.    tags = [...tags, ...tagsOfIsp, ...tagsOfEcommerce];
  28.   stores = [...stores, ...isps, ...ecommerces];
  29.  
  30.   res.json({tags, stores});
  31.  
  32. }
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