-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feature(profile-update): implement feedback changes and rebase off de…
…velop
- Loading branch information
Showing
20 changed files
with
393 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -33,6 +33,7 @@ node_modules | |
|
||
# Optional npm cache directory | ||
.npm | ||
uploads | ||
|
||
# Optional REPL history | ||
.node_repl_history | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
module.exports = { | ||
up: (queryInterface, Sequelize) => { | ||
return queryInterface.addColumn('Users', 'bio', { | ||
type: Sequelize.TEXT, | ||
allowNull: true | ||
}); | ||
}, | ||
down: queryInterface => { | ||
return queryInterface.removeColumn('Users', 'bio'); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
module.exports = { | ||
up: (queryInterface, Sequelize) => { | ||
return queryInterface.addColumn('Users', 'facebookHandle', { | ||
type: Sequelize.STRING, | ||
allowNull: true | ||
}); | ||
}, | ||
down: queryInterface => { | ||
return queryInterface.removeColumn('Users', 'facebookHandle'); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
module.exports = { | ||
up: (queryInterface, Sequelize) => { | ||
return queryInterface.addColumn('Users', 'twitterHandle', { | ||
type: Sequelize.STRING, | ||
allowNull: true | ||
}); | ||
}, | ||
down: queryInterface => { | ||
return queryInterface.removeColumn('Users', 'twitterHandle'); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import cloudinary from 'cloudinary'; | ||
import fs from 'fs'; | ||
|
||
cloudinary.config({ | ||
cloud_name: process.env.CLOUDINARY_NAME, | ||
api_key: process.env.CLOUDINARY_API_KEY, | ||
api_secret: process.env.CLOUDINARY_API_SECRET | ||
}); | ||
/** | ||
* Handles the upload of image to cloudinary | ||
* | ||
* @param {string} path | ||
* @param {string} uniqueFilename | ||
* @returns {object} uploaded image response | ||
*/ | ||
const upload = async (path, uniqueFilename) => { | ||
return cloudinary.v2.uploader.upload( | ||
path, | ||
{ public_id: `avatar/${uniqueFilename}`, tags: `avatar` }, // directory and tags are optional | ||
image => { | ||
// remove file from server | ||
fs.unlinkSync(path); | ||
// return image details | ||
return image; | ||
} | ||
); | ||
}; | ||
export default upload; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import multer from 'multer'; | ||
|
||
const fileFilter = (request, file, callback) => { | ||
const error = new Error('Only JPG/PNG images are allowed'); | ||
error.status = 422; | ||
// accept only jpg or png images | ||
if (file.mimetype === 'image/jpeg' || file.mimetype === 'image/png') { | ||
callback(null, true); | ||
} else { | ||
callback(error, false); | ||
} | ||
}; | ||
|
||
const storage = multer.diskStorage({ | ||
destination: (request, file, callback) => { | ||
callback(null, 'uploads/'); | ||
}, | ||
filename: (request, file, callback) => { | ||
callback(null, new Date().toISOString() + file.originalname); | ||
} | ||
}); | ||
|
||
const upload = multer({ | ||
storage, | ||
fileFilter, | ||
limits: { | ||
fileSize: 1024 * 1024 * 5 | ||
} | ||
}); | ||
|
||
export default upload; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import { findByUserName, findUserById } from '../services/auth.service'; | ||
import Helper from '../services/helper'; | ||
/** | ||
* | ||
* @description Handles neccessary checks on profile update | ||
* @param {object} request | ||
* @param {object} response | ||
* @param {function} next | ||
* @returns {(function|Object)} Function next() or an error Object | ||
*/ | ||
const profileChecks = async (request, response, next) => { | ||
try { | ||
const userInstance = await findUserById(request.user.id); | ||
if (!userInstance) { | ||
return Helper.failResponse(response, 404, { | ||
message: 'User account does not exist' | ||
}); | ||
} | ||
|
||
if (request.body.userName) { | ||
const userNameExists = await findByUserName(request.body.userName); | ||
const { id } = userNameExists; | ||
if (userNameExists && id !== request.user.id) { | ||
return Helper.failResponse(response, 409, { | ||
message: 'Username has already been taken' | ||
}); | ||
} | ||
} | ||
request.foundUser = userInstance; | ||
|
||
return next(); | ||
} catch (error) { | ||
return Helper.errorResponse(response, 500, error); | ||
} | ||
}; | ||
|
||
export default { profileChecks }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.