mirror of
https://bitbucket.org/tagfer_team/tagfer-server.git
synced 2025-12-25 03:37:38 +00:00
T-954157790482088: bug fixes based on code review changes
This commit is contained in:
parent
bdcd675c9c
commit
97f7d7bc92
@ -115,8 +115,8 @@ function createNewSessionId(tagferId) {
|
||||
function getSession(id) {
|
||||
const sessions = loki.getCollection("sessions");
|
||||
var session = sessions.by('id', id)
|
||||
if (!_.isEmpty(session) ) {
|
||||
return session[0];
|
||||
if (session) {
|
||||
return session;
|
||||
} else {
|
||||
throw errors.AUTH_INVALID_SESSION_ID;
|
||||
}
|
||||
|
||||
@ -2,7 +2,8 @@ const authDao = require('./dao');
|
||||
const profileDao = require('./../profiles/dao');
|
||||
const utils = require('../utils/utils');
|
||||
const errors = require('../../config/errors');
|
||||
const appConfig = require('../../config/app.json')
|
||||
const appConfig = require('../../config/app.json');
|
||||
const http = require('../../config/http');
|
||||
|
||||
// Handlers
|
||||
/**
|
||||
@ -113,19 +114,16 @@ function signup(req, res) {
|
||||
const sessionId = authDao.createNewSessionId(user.uid);
|
||||
try {
|
||||
const tagferId = authDao.getSession(sessionId).tagferId;
|
||||
profileDao.createInitialProfiles(profile,tagferId).then ((result) => { //for some reason this callback is not returning the data populated by promise
|
||||
if (result.result) {
|
||||
profileDao.createInitialProfiles(profile,tagferId).then (() => {
|
||||
res.json({sessionId});
|
||||
} else {
|
||||
res.json( {error: result.error});
|
||||
}
|
||||
}).catch((error) => {
|
||||
res.status(http.BAD_REQUEST).json({error});
|
||||
})
|
||||
} catch (error) {
|
||||
res.status(http.BAD_REQUEST).json({error});
|
||||
}
|
||||
}).catch(error => {
|
||||
error = error.code
|
||||
res.json( {error: error.code} );
|
||||
res.json( {error} );
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
@ -5,13 +5,9 @@ const database = require('firebase-admin').database();
|
||||
* @param {object} profileObj
|
||||
* @param {string} tagferId
|
||||
*/
|
||||
async function createInitialProfiles(profileObj, tagferId) {
|
||||
function createInitialProfiles(profileObj, tagferId) {
|
||||
//persist profile data to firebase
|
||||
await database.ref(`/profiles/${tagferId}/profile1`).set(profileObj).then( () => {
|
||||
return {result:true};
|
||||
}).catch( (error) => {
|
||||
return {result:false, error};
|
||||
});
|
||||
return database.ref(`/profiles/${tagferId}/profile1`).set(profileObj);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -21,13 +17,9 @@ async function createInitialProfiles(profileObj, tagferId) {
|
||||
* @param {string} tagferId tagferId obtained by extracting from authorization header
|
||||
* @returns {Boolean} Boolean result of whether the
|
||||
*/
|
||||
async function updateProfile(profileObj, profileNumber, tagferId) {
|
||||
function updateProfile(profileObj, profileNumber, tagferId) {
|
||||
//persist profile data to firebase
|
||||
await database.ref(`/profiles/${tagferId}/profile${profileNumber}`).update(profileObj).then( () => {
|
||||
return {result:true};
|
||||
}).catch( (error) => {
|
||||
return {result:false, error};
|
||||
});
|
||||
return database.ref(`/profiles/${tagferId}/profile${profileNumber}`).update(profileObj);
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
|
||||
@ -17,16 +17,8 @@ async function updateUserProfile(req, res) {
|
||||
const sessionId = utils.getSessionIdFromAuthHeader(req, res);
|
||||
try {
|
||||
const tagferId = authDao.getSession(sessionId).tagferId;
|
||||
var createRes = profileDao.updateProfile(profileObj, req.params.profileNumber, tagferId).then( (createRes) => {
|
||||
if (createRes.result) {
|
||||
res.status(http.CREATED).json({})
|
||||
} else {
|
||||
if (createRes.error) {
|
||||
res.status(http.BAD_REQUEST).json({ error: createRes.error})
|
||||
} else {
|
||||
res.status(http.INTERNAL_SERVER_ERROR).json({ error: errors.MAX_NUMBER_OF_PROFILES_REACHED});
|
||||
}
|
||||
}
|
||||
profileDao.updateProfile(profileObj, req.params.profileNumber, tagferId).then( () => {
|
||||
res.status(http.CREATED).json({})
|
||||
}).catch( (error) => {
|
||||
res.status(http.INTERNAL_SERVER_ERROR).json({error: "Promise error unknown"})
|
||||
});
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user