mirror of
https://bitbucket.org/tagfer_team/tagfer-server.git
synced 2025-12-25 03:37:38 +00:00
T-954157790456099: Add endpoint for getting user profiles
This commit is contained in:
parent
aece58471e
commit
1271b2dfe6
@ -21,7 +21,7 @@ function router(app) {
|
||||
|
||||
// Profile Endpoints
|
||||
app.post('/profiles/:profileNumber', ProfileHandlers.updateUserProfile);
|
||||
app.get('profiles/:profileNumber', ProfileHandlers.getUserProfile);
|
||||
app.get('/profiles/:profileNumber', ProfileHandlers.getUserProfile);
|
||||
}
|
||||
|
||||
module.exports = router;
|
||||
@ -25,25 +25,17 @@ function updateProfile(profileObj, profileNumber, tagferId) {
|
||||
/**
|
||||
* 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
|
||||
*/
|
||||
async function getProfile(profileNumber) {
|
||||
//get tagfer-id from loki
|
||||
const sessions = loki.getCollection("sessions");
|
||||
const primarySession = sessions.get(1);
|
||||
const tagferId = primarySession.tagferId;
|
||||
|
||||
var profile = null;
|
||||
await database.ref(`/profiles/${tagferId}/profile${profileNumber}`).once('value').then(function(snapshot) {
|
||||
if (snapshot.val()) {
|
||||
profile = snapshot.val();
|
||||
}
|
||||
function getProfile(profileNumber, tagferId) {
|
||||
return database.ref(`/profiles/${tagferId}/profile${profileNumber}`).once('value').then(function(snapshot) {
|
||||
return snapshot.val();
|
||||
});
|
||||
return profile;
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
updateProfile,
|
||||
createInitialProfiles
|
||||
createInitialProfiles,
|
||||
getProfile
|
||||
};
|
||||
|
||||
@ -34,20 +34,24 @@ async function updateUserProfile(req, res) {
|
||||
}
|
||||
|
||||
async function getUserProfile(req, res) {
|
||||
const { profileNumber } = req.param;
|
||||
|
||||
var profile = dao.getProfile(profileNumber).then( (profile) => {
|
||||
if (profile) {
|
||||
res.json({ profile, status: http.OK})
|
||||
} else {
|
||||
res.json({error: errors.NO_PROFILE_FOUND_FOR_NUMBER , status: http.BAD_REQUEST})
|
||||
}
|
||||
}).catch( error => {
|
||||
res.json({status: http.INTERNAL_SERVER_ERROR, error})
|
||||
})
|
||||
const sessionId = utils.getSessionIdFromAuthHeader(req, res);
|
||||
try {
|
||||
const tagferId = authDao.getSession(sessionId).tagferId;
|
||||
profileDao.getProfile(req.params.profileNumber,tagferId).then((profile) => {
|
||||
if (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 })
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
updateUserProfile
|
||||
updateUserProfile,
|
||||
getUserProfile
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user