mirror of
https://bitbucket.org/tagfer_team/tagfer-server.git
synced 2025-12-25 03:37:38 +00:00
Merge branch 'T-954157790456099-User-Can-View-And-Edit-Each-Profile'
This commit is contained in:
commit
506166b146
@ -21,5 +21,5 @@ module.exports = {
|
||||
MISSING_BODY_ATTRIBUTES: 'request/missing-body-attributes',
|
||||
//Profile Errors
|
||||
MAX_NUMBER_OF_PROFILES_REACHED: 'profile/max-number-of-profiles-are-being-used',
|
||||
NO_PROFILE_FOUND_FOR_NUMBER: 'profile/no-profile-found-for-number'
|
||||
NO_PROFILE_FOUND_FOR_NUMBER: 'profile/no-profile-was-found-for-the-profile-number-passed',
|
||||
};
|
||||
@ -21,6 +21,7 @@ function router(app) {
|
||||
|
||||
// Profile Endpoints
|
||||
app.post('/profiles/:profileNumber', ProfileHandlers.updateUserProfile);
|
||||
app.get('/profiles/:profileNumber', ProfileHandlers.getUserProfile);
|
||||
}
|
||||
|
||||
module.exports = router;
|
||||
@ -22,7 +22,20 @@ function updateProfile(profileObj, profileNumber, tagferId) {
|
||||
return database.ref(`/profiles/${tagferId}/profile${profileNumber}`).set(profileObj);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a user profile
|
||||
* @param {Number} profileNumber profile number that identifies which profile information to get for a user
|
||||
* @param {string} tagferId SessionId obtained by extracting from authorization header
|
||||
* @returns {Object} Profile object containg information for a specific user's profile
|
||||
*/
|
||||
function getProfile(profileNumber, tagferId) {
|
||||
return database.ref(`/profiles/${tagferId}/profile${profileNumber}`).once('value').then(function(snapshot) {
|
||||
return (snapshot.exists() ? snapshot.val() : {});
|
||||
});
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
updateProfile,
|
||||
createInitialProfiles
|
||||
createInitialProfiles,
|
||||
getProfile
|
||||
};
|
||||
|
||||
@ -18,21 +18,39 @@ async function updateUserProfile(req, res) {
|
||||
|
||||
if (!utils.isProfileNumberValid(profileNumber, res)) {
|
||||
return;
|
||||
} else {
|
||||
const sessionId = utils.getSessionIdFromAuthHeader(req, res);
|
||||
try {
|
||||
const tagferId = authDao.getSession(sessionId).tagferId;
|
||||
profileDao.updateProfile(profileObj, profileNumber, tagferId).then( () => {
|
||||
res.status(http.CREATED).json({})
|
||||
}).catch( (error) => {
|
||||
res.status(http.INTERNAL_SERVER_ERROR).json({error: errors.APP_FIREBASE_DATABASE_ERROR})
|
||||
});
|
||||
} catch (error) {
|
||||
res.status(http.UNAUTHORIZED).json({error})
|
||||
}
|
||||
}
|
||||
const sessionId = utils.getSessionIdFromAuthHeader(req, res);
|
||||
try {
|
||||
const tagferId = authDao.getSession(sessionId).tagferId;
|
||||
profileDao.updateProfile(profileObj, profileNumber, tagferId).then( () => {
|
||||
res.status(http.CREATED).json({})
|
||||
}).catch( (error) => {
|
||||
res.status(http.INTERNAL_SERVER_ERROR).json({error: errors.APP_FIREBASE_DATABASE_ERROR})
|
||||
});
|
||||
} catch (error) {
|
||||
res.status(http.UNAUTHORIZED).json({error})
|
||||
}
|
||||
}
|
||||
|
||||
async function getUserProfile(req, res) {
|
||||
const profileNumber = req.params.profileNumber;
|
||||
if (!utils.isProfileNumberValid(profileNumber)) {
|
||||
return;
|
||||
}
|
||||
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})
|
||||
}).catch(error => {
|
||||
res.status(http.INTERNAL_SERVER_ERROR).json({error: error.code})
|
||||
})
|
||||
} catch (error) {
|
||||
res.status(http.UNAUTHORIZED).json({ error })
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
updateUserProfile
|
||||
updateUserProfile,
|
||||
getUserProfile
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user