0

I'm working with Parse.com's Cloud Code to implement Mailgun and Stripe Cloud Methods.

When a Stripe payment is successfully charged, I use Mailgun to send an email to the user.

I've stored a company email "signature logo" on Parse, and I'd like to (optionally) get it to append to the HTML of the email I'm crafting. (Basically, getting the PFFile's url() and setting that as the src of an img).

I've got the "email crafting" code working fine, and I'm now just trying to get the logo's url and append it at the end of the email.

I thought I'd use promises to make my code cleaner, but it turns out I have a problem:

I want the same code to run whether my query returns a value or not. If so, I'll append the img tag; if not, I'll skip adding the image.

In the interest of DRY (D on't R epeat Y ourself), I'd prefer to not enter essentially the same code twice, once on the success pathway and once on the failure pathway.

Based on the (somewhat) convoluted way Parse requires you to call other methods, I'd prefer to not wrap it up in another method (though I'm guessing that's the "right" thing to do here).

Is there any way to run a Parse.com JavaScript SDK Query synchronously?

Any other ideas for this scenario?

mbm29414
  • 11,558
  • 6
  • 56
  • 87
  • Could you perhaps show us the code that you think needs improvement? It's a little hard to understand your problem. You should not run queries synchronously, even if you could. – Tom Erik Støwer Sep 23 '14 at 06:58
  • @TomErikStøwer I avoided posting the code because I copied the sample from the Parse Store app, and their "make a purchase and send a confirmation email" method is really, really long. I ended up learning more about Parse Promises and figured out how to pass the query results on to a `then()` Promise either way, which worked for me. I think I'll tidy it up and post it as an answer. – mbm29414 Sep 23 '14 at 13:25

0 Answers0