SHARE
TWEET

Untitled

a guest Mar 20th, 2017 67 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /* Notes:
  2. Async/Sync
  3. For the sake of simplicity, we aren't going to use Promises or callback
  4. functions, but assume their implementation.
  5. */
  6. create(request, response) {
  7.     // Create User
  8.     let password = library.generate_password();
  9.     let created_user = Models.user.create({
  10.         name: request.body.name,
  11.         email: request.body.email,
  12.         phone: request.body.phone,
  13.         password: password,
  14.         created_by: auth_user.id
  15.     });
  16.  
  17.     response.status(200).json({
  18.         user: {}
  19.     });
  20.  
  21.     // Async non-blocking actions
  22.     // Send new user email
  23.     emails.send('user_created', {
  24.         email: request.body.email
  25.     });
  26.     // Alert sales team of new user creation
  27.     emails.send('internal_user_created', {
  28.         url: 'fake-url-to-new-user-page'
  29.     });
  30.     // Alert sales team via Slack
  31.     slack.new_user_added({
  32.         url: 'fake-url-to-new-user-page'
  33.     });
  34.     // Add new user to SalesForce
  35.     salesforce.add_user({
  36.         name: request.body.name,
  37.         email: request.body.email,
  38.         phone: request.body.phone
  39.     });
  40.     // Send user their password via SMS
  41.     sms.send_password({
  42.         phone: request.body.phone,
  43.         password: password
  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