mirror of
https://bitbucket.org/tagfer_team/tagfer-server.git
synced 2025-12-25 03:37:38 +00:00
T-954157790456099: add get endpoint to retrieve user profile by number
This commit is contained in:
parent
4a74028aee
commit
aece58471e
@ -21,4 +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-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,28 @@ 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
|
||||
* @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();
|
||||
}
|
||||
});
|
||||
return profile;
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
updateProfile,
|
||||
createInitialProfiles
|
||||
getProfile
|
||||
};
|
||||
|
||||
@ -33,6 +33,21 @@ 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})
|
||||
})
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
updateUserProfile
|
||||
getUserProfile
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user