T-954157790456099: code review comments

This commit is contained in:
Okechi Onyeje 2018-12-31 09:18:53 -05:00
parent 1271b2dfe6
commit 2449b207da
2 changed files with 15 additions and 14 deletions

View File

@ -30,7 +30,7 @@ function updateProfile(profileObj, profileNumber, tagferId) {
*/
function getProfile(profileNumber, tagferId) {
return database.ref(`/profiles/${tagferId}/profile${profileNumber}`).once('value').then(function(snapshot) {
return snapshot.val();
return (snapshot.exists() ? snapshot.val() : {});
});
}

View File

@ -34,20 +34,21 @@ async function updateUserProfile(req, res) {
}
async function getUserProfile(req, res) {
const sessionId = utils.getSessionIdFromAuthHeader(req, res);
try {
const tagferId = authDao.getSession(sessionId).tagferId;
profileDao.getProfile(req.params.profileNumber,tagferId).then((profile) => {
if (profile) {
const profileNumber = req.params.profileNumber;
if (profileNumber > 4 || profileNumber < 1) {
res.status(http.BAD_REQUEST).json({error: errors.NO_PROFILE_FOUND_FOR_NUMBER});
} else {
const sessionId = utils.getSessionIdFromAuthHeader(req, res);
try {
const tagferId = authDao.getSession(sessionId).tagferId;
profileDao.getProfile(profileNumber,tagferId).then((profile) => {
res.status(http.OK).json({profile})
} else {
res.status(http.BAD_REQUEST).json({ error: errors.NO_PROFILE_FOUND_FOR_NUMBER})
}
}).catch(error => {
res.status(http.INTERNAL_SERVER_ERROR).json({error})
})
} catch (error) {
res.status(http.BAD_REQUEST).json({ error })
}).catch(error => {
res.status(http.INTERNAL_SERVER_ERROR).json({error: error.code})
})
} catch (error) {
res.status(http.UNAUTHORIZED).json({ error })
}
}
}