module.exports.addPokemon = function (req, res) {
  var name = req.body.name.toLowerCase();
  P.getPokemonByName(name)
  .then(function(pokemon) {
    console.log('pokemon is', pokemon);
    Pokemon.findOne({name:name}, function(err, result) {
      if(err){
        res.sendStatus(500);
      }
      if(result) {
        res.sendStatus(200);
      }else{
        Pokemon({name:name, weight:pokemon.weight, height:pokemon.height, image:pokemon.sprites.front_default, star:false}).save(function(err,result) {
          if(err) {
            res.sendStatus(500);
          }else{
            res.sendStatus(201);
          }
        })
      }
    });
  })
  .catch(function(error) {
    console.log('There was an ERROR: ', error);
    res.status(404);
    res.send(error);
  });
};
Exemple #2
0
function encounter(){

var random = Math.floor(Math.random() * 700);

P.getPokemonByName(random, function(response, error) { // with callback
      if(!error) {
      	pokemon = response.name;
      	console.log("--------------------------------------------------------");
        console.log('A random ' + response.name + ' appeared!');
        console.log("--------------------------------------------------------");

        inquirer.prompt([{
        	type: 'confirm',
        	name: 'boolean',
        	message: 'Would you like to try and catch it?'
        }]).then(function (choice){
        	//console.log(choice);
        	if(choice.boolean){
        		//run probablity/catching function
        		catchPokemon();
        	}
        })
      } else {
        console.log(error)
      }
    });

};
router.get('/browse', function (req, res) {
  P.getPokemonByName('?limit=151')
  .then(function (response) {
    res.send(response);
  })
  .catch(function (err) {
    console.log('Error: ', err);
  })
})
router.get('/details/:pokemon', function (req, res) {
  P.getPokemonByName(req.params.pokemon)
  .then(function (response) {
    res.send(response);
  })
  .catch(function (err) {
    console.log('Error: ', err);
  })
})
Exemple #5
0
ImageList.getImageList = function(q,list,max,classifier,callback){
	var self = this;
	P.getPokemonByName(q.toLowerCase()).then(function(){
		self.getPokeImageCount(q,function(count){
			var num = count || 1;
			return ImageList.getValidatedImageList(q,list,num,num+max,classifier,function(images){
				callback(images);
			});
		});
	}).catch(function(error){
		callback({error:true,message:"No pokemon found called "+q,data:error});
	});
}
					.then(function(){
						P.getPokemonByName(name)
	    					.then(function(response) {
	    					var src = response.sprites.front_default;
	    					console.log(src);
	    					name = response.name;
	    					db.none('INSERT INTO team(user_id,name, src) values(${user_id}, ${name}, ${src})', { user_id: user_id, 
							name: name, src: src})
	      					res.redirect('/team/' + user_id);
	      				})
	    				.catch(function(error) {
	      				console.log('There was an ERROR: ', error);
	    				});
					})
Exemple #7
0
 validatePokemon: function(name, cb) {
     var t = P.getPokemonByName(name);
     if (t.then) {
         t.then(function(response) {
                 cb(false, response);
             })
             .catch(function(error) {
                 console.log('There was an ERROR: ', error);
                 var message = 'Your Pokemon name is not valid. Please try again.';
                 error = true;
                 cb(true, message);
             });
     } else {
         cb(true, t);
     }
 },
Exemple #8
0
PokeImage.getImageByKeyword = function(keyword,callback){
	P.getPokemonByName(keyword.toLowerCase()).then(function(){
		MongoClient.connect(secrets.mongo_url,function(err,db){
			if (err){
				callback(false);
				return;
			}

			findImage({keyword:keyword,tags:{"$not":{"$size":0}}},db,function(image){
				if (!image){
					callback(null);
					return;
				}

				callback(image);
			});
		});
	}).catch(function(error){
		return {error:true,message:"No pokemon found called "+keyword,data:error};
	});
}