From 060154fa3e3910eb06af3e656df102367df39067 Mon Sep 17 00:00:00 2001 From: Okechi Onyeje Date: Mon, 31 Dec 2018 08:49:56 -0500 Subject: [PATCH] T-954157790482088: Code review comments addressed --- src/config/errors.js | 1 + src/ups/auth/handlers.js | 10 +++------- src/ups/profiles/handlers.js | 4 ++-- src/ups/utils/utils.js | 1 - 4 files changed, 6 insertions(+), 10 deletions(-) diff --git a/src/config/errors.js b/src/config/errors.js index 0747bdc..60d8e56 100644 --- a/src/config/errors.js +++ b/src/config/errors.js @@ -16,6 +16,7 @@ module.exports = { APP_NETWORK_ERROR: 'app/network-error', APP_NETWORK_TIMEOUT: 'app/network-timeout', APP_UNABLE_TO_PARSE_RESPONSE: 'app/unable-to-parse-response', + APP_FIREBASE_DATABASE_ERROR: 'app/firebase-database-error', //Request Errors MISSING_BODY_ATTRIBUTES: 'request/missing-body-attributes', //Profile Errors diff --git a/src/ups/auth/handlers.js b/src/ups/auth/handlers.js index c795753..fc24253 100644 --- a/src/ups/auth/handlers.js +++ b/src/ups/auth/handlers.js @@ -98,23 +98,19 @@ function signin(req, res) { function signup(req, res) { const {user, profile} = req.body; const userVerifier = () => user.tagferId && user.email && user.password && user.phoneNumber && user.fullName; - const profileVerifier = () => profile.title && profile.companyTxt && profile.addressTxt; + const profileVerifier = () => profile.company && profile.company.profession && profile.company.name && profile.company.address && profile.company.number; if (!utils.isAppSecretValid(req,res) || !utils.isBodyValid(userVerifier, res) || !utils.isBodyValid(profileVerifier, res)) { return; } - if (!profile.contactNumbers || (profile.contactNumbers && !profile.contactNumbers.primary)) { - profile.contactNumbers = {primary: user.phoneNumber}; - profile.name = appConfig.defaultProfileName; - } + profile.name = appConfig.defaultProfileName; profile.email = user.email authDao.createNewUser(user).then( user => { const sessionId = authDao.createNewSessionId(user.uid); try { - const tagferId = authDao.getSession(sessionId).tagferId; - profileDao.createInitialProfiles(profile,tagferId).then (() => { + profileDao.createInitialProfiles(profile,user.tagferId).then (() => { res.json({sessionId}); }).catch((error) => { res.status(http.BAD_REQUEST).json({error}); diff --git a/src/ups/profiles/handlers.js b/src/ups/profiles/handlers.js index 8641c8d..9562135 100644 --- a/src/ups/profiles/handlers.js +++ b/src/ups/profiles/handlers.js @@ -20,10 +20,10 @@ async function updateUserProfile(req, res) { profileDao.updateProfile(profileObj, req.params.profileNumber, tagferId).then( () => { res.status(http.CREATED).json({}) }).catch( (error) => { - res.status(http.INTERNAL_SERVER_ERROR).json({error: "Promise error unknown"}) + res.status(http.INTERNAL_SERVER_ERROR).json({error: errors.APP_FIREBASE_DATABASE_ERROR}) }); } catch (error) { - res.status(http.BAD_REQUEST).json({error}) + res.status(http.UNAUTHORIZED).json({error}) } } diff --git a/src/ups/utils/utils.js b/src/ups/utils/utils.js index ace5dce..a4a3699 100644 --- a/src/ups/utils/utils.js +++ b/src/ups/utils/utils.js @@ -27,7 +27,6 @@ function getSessionIdFromAuthHeader(req, res) { if (usrToken) { return usrToken; } else { - res.status(http.UNAUTHORIZED).json({ error: errors.AUTH_UNABLE_TO_EXTRACT_SESSION_ID_FROM_AUTH_HEADER }); return null; } }