T-954157790482088: Refactor signup endpoint using awaits

This commit is contained in:
Okechi Onyeje 2019-01-01 21:02:32 -05:00
parent 59d2530d09
commit e055b608fa
2 changed files with 10 additions and 17 deletions

View File

@ -182,7 +182,7 @@ module.exports = {
signinWithEmail,
createNewUser,
createNewSessionId,
getSession
getSession,
resetPassword
};

View File

@ -95,7 +95,7 @@ function signin(req, res) {
* @param {Object} req { tagferId: String, email: String, password: String, phoneNumber: String, fullName: String }
* @param {Object} res { sessionId: String } | { error: String }
*/
function signup(req, res) {
async function signup(req, res) {
const {user, profile} = req.body;
const userVerifier = () => user.tagferId && user.email && user.password && user.phoneNumber && user.fullName;
const profileVerifier = () => profile.company && profile.company.profession && profile.company.name && profile.company.address && profile.company.number;
@ -107,21 +107,14 @@ function signup(req, res) {
profile.name = appConfig.defaultProfileName;
profile.email = user.email
authDao.createNewUser(user).then( user => {
const sessionId = authDao.createNewSessionId(user.uid);
try {
profileDao.createInitialProfiles(profile,user.uid).then (() => {
res.json({sessionId});
}).catch((error) => {
res.status(http.BAD_REQUEST).json({error});
})
} catch (error) {
res.status(http.BAD_REQUEST).json({error});
}
}).catch(error => {
res.json( {error} );
});
try {
await authDao.createNewUser(user);
await profileDao.createInitialProfiles(profile, user.tagferId);
const sessionId = authDao.createNewSessionId(user.tagferId);
res.status(http.CREATED).json({sessionId});
} catch (error) {
res.status(http.BAD_REQUEST).json({error:error.code});
}
}
/**