mirror of
https://bitbucket.org/tagfer_team/tagfer-server.git
synced 2025-12-25 03:37:38 +00:00
T-954157790456099: code review comments
This commit is contained in:
parent
1271b2dfe6
commit
2449b207da
@ -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() : {});
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@ -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 })
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user