Skip to content

Instantly share code, notes, and snippets.

@JoeTheDave
Created July 21, 2016 02:59
Show Gist options
  • Save JoeTheDave/44c71cc88d44492fd8bd2cb590b8c97d to your computer and use it in GitHub Desktop.
Save JoeTheDave/44c71cc88d44492fd8bd2cb590b8c97d to your computer and use it in GitHub Desktop.
'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
};
@dynajoe
Copy link

dynajoe commented Jul 21, 2016

I want to go over this code more with you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment