Created
July 21, 2016 02:59
-
-
Save JoeTheDave/44c71cc88d44492fd8bd2cb590b8c97d to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict'; | |
const appUserRepository = require('../data/repositories/appUserRepository'); | |
const saveAppUser = (profile) => { | |
return new Promise((resolve, reject) => { | |
Promise.resolve().then(() => { | |
return appUserRepository.getAppUserByFacebookId(profile.id); | |
}).then((appUser) => { | |
if (appUser) { | |
return appUserRepository.updateAppUser(profile); | |
} else { | |
return appUserRepository.insertAppUser(profile); | |
} | |
}).then((facebookId) => { | |
return appUserRepository.getAppUserByFacebookId(facebookId); | |
}).then((appUser) => { | |
if (!appUser) { throw 'An error occurred attempting to save appUser.'; } | |
resolve(appUser); | |
}).catch((error) => { | |
reject(error); | |
}); | |
}); | |
}; | |
module.exports = { | |
saveAppUser: saveAppUser | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I want to go over this code more with you.