I'm not being able to exit a method when returning an alert. For example i have here two validations "hasEventWithExternalId" and "isValidFacebookEvent",if i try the same event more than once the result of "hasEventWithExternalId" turns true and it returns the alert, but then the execution of the method continues and creates a new event and returns the success alert. Any ideas on wahts happening?
Template.eventnew.events({
'click #btn-event-data': function(e) {
//Check if facebook event was already imported
Meteor.call('hasEventWithExternalId', id, function(error, result) {
if(result){
return swal({
title: "Event already imported from Facebook",
text: "That facebook event was already imported to this application",
showConfirmButton: true,
type: "error"
});
}
});
//Check if it is a valid facebook event
Meteor.call('isValidFacebookEvent', id, function(error, result) {
if(!result){
return swal({
title: "Invalid Facebook event",
text: "That's not a valid facebook event'",
showConfirmButton: true,
type: "error"
});
}
});
Meteor.call('importEventFromFacebook', id, function(error, result) {
if(error){
console.log(error);
return false;
}
else{
return swal({
title: "Event sucessfully imported",
showConfirmButton: true,
type: "success"
});
}
});
}
One of the methods:
Meteor.methods({
//Check if Event with external id x already exists
hasEventWithExternalId: function(externalId){
if(Event.find({externalId: externalId}).count()>0)
return true;
else
return false;
}
});