T-954157790482076: Code review comments

- removed response variable from utility and dao function signatures
This commit is contained in:
Okechi Onyeje 2019-01-12 18:37:08 -05:00
parent b4c93b96ec
commit b50fe3e951
3 changed files with 12 additions and 20 deletions

View File

@ -44,10 +44,14 @@ function getProfile(profileNumber, tagferId) {
* @returns {object} Object containing a Promise that contains the result of uploading profile image, and the image url | {promise, imageURL}
*/
async function updateProfileImage(profileImageData, profileNumber, tagferId, res) {
async function updateProfileImage(profileImageData, profileNumber, tagferId) {
//persist profile image data to firebase storage
var downloadURL = await utils.uploadImage(profileImageData, `${tagferId}-profile${profileNumber}`, appConfig.buckets.profile, res);
return { promise: database.ref(`/profiles/${tagferId}/profile${profileNumber}/photoURL`).set(downloadURL), imageURL: downloadURL };
try {
var downloadURL = await utils.uploadImage(profileImageData, `${tagferId}-profile${profileNumber}`, appConfig.buckets.profile);
return { promise: database.ref(`/profiles/${tagferId}/profile${profileNumber}/photoURL`).set(downloadURL), imageURL: downloadURL };
} catch (error) {
throw error;
}
}
module.exports = {

View File

@ -3,7 +3,6 @@ const authDao = require('../auth/dao');
const utils = require('../utils/utils');
const errors = require('../../config/errors');
const http = require('../../config/http');
const _ = require('lodash');
// Handlers
/**
@ -45,7 +44,7 @@ async function updateUserProfileImage(req, res) {
try {
const tagferId = authDao.getSession(sessionId).tagferId;
const result = await profileDao.updateProfileImage(profileImageObj, req.params.profileNumber, tagferId, res)
const result = await profileDao.updateProfileImage(profileImageObj, req.params.profileNumber, tagferId);
result.promise.then(() => {
res.status(http.OK).json({ imageURL: result.imageURL });
}).catch((error) => {

View File

@ -1,10 +1,8 @@
const OAuth = require('oauth-1.0a');
const crypto = require('crypto');
const appConfig = require('../../config/app.json');
const http = require('../../config/http');
const errors = require('../../config/errors');
const UUID = require('uuid/v4');
const firebase = require('firebase-admin');
/**
@ -81,22 +79,14 @@ function createOAuthHeader(request, app) {
*
* @returns {*} imageURL
*/
async function uploadImage(imageData, path, bucketName, res) {
async function uploadImage(imageData, path, bucketName) {
try {
const bucket = await firebase.storage().bucket(`gs://${bucketName}`);
const bucket = firebase.storage().bucket(`gs://${bucketName}`);
var file = bucket.file(`${path}.${appConfig.imageFormat[imageData.metaData.contentType]}`);
const uuid = UUID();
var imageBuffer = new Buffer(imageData.base64Data, 'base64');
var imageBuffer = Buffer.from(imageData.base64Data, 'base64');
await file.save(imageBuffer, {
metaData: {
contentType: imageData.metaData.contentType,
metadata: {
firebaseStorageDownloadTokens: uuid
}
},
public: true,
validation: 'md5',
});
@ -105,8 +95,7 @@ async function uploadImage(imageData, path, bucketName, res) {
return fileMetaData[0].mediaLink;
} catch (error) {
res.status(http.INTERNAL_SERVER_ERROR).json({error});
return null;
throw error;
}
}