SHARE
TWEET

Untitled

a guest Feb 14th, 2020 75 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. module.exports = {
  2.  
  3.   //List all users registered in Upics
  4.   async ListAllUsers(req, res) {
  5.     try {
  6.  
  7.       //Query to users collections
  8.       const pruebas = [];
  9.       const ListUsers = await users.find();
  10.  
  11.       pruebas.push(ListUsers);
  12.  
  13.       //detect if exist info
  14.       if (pruebas.length == "") {
  15.         return res.serverError({
  16.           err: "Users not found"
  17.         });
  18.       } else {
  19.  
  20.         //load all users
  21.         for (let i=0; i <= pruebas.length -1 ; i++) {
  22.  
  23.           //empty array
  24.           const info = [];
  25.  
  26.           for (let j = 0; j <= pruebas[i].length - 1; j++) {
  27.             info.push({
  28.               username:pruebas[""]
  29.             });
  30.           }
  31.  
  32.           console.log(info);
  33.  
  34.         }
  35.       }
  36.  
  37.     } catch (err) {
  38.       if (err.name === "ValidateError") {
  39.         return res.badRequest({err: 'Not found users!'});
  40.       } else {
  41.         return res.serverError({err:"Error, try again!"});
  42.       }
  43.     }
  44.   }
  45. };
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