T-954157790482088: Code review comments addressed

This commit is contained in:
Okechi Onyeje 2018-12-31 08:49:56 -05:00
parent 9821395449
commit 060154fa3e
4 changed files with 6 additions and 10 deletions

View File

@ -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

View File

@ -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});

View File

@ -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})
}
}

View File

@ -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;
}
}