-
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.
- Loading branch information
Showing
23 changed files
with
395 additions
and
84 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
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,21 @@ | ||
import cloudinary from 'cloudinary'; | ||
cloudinary.config({ | ||
cloud_name: process.env.CLOUDINARY_NAME, | ||
api_key: process.env.CLOUDINARY_API_KEY, | ||
api_secret: process.env.CLOUDINARY_API_SECRET | ||
}); | ||
|
||
export const upload = async (path, uniqueFilename) => { | ||
return cloudinary.v2.uploader.upload( | ||
path, | ||
{ public_id: `avatar/${uniqueFilename}`, tags: `avatar` }, // directory and tags are optional | ||
image => { | ||
console.log('file uploaded to Cloudinary'); | ||
// remove file from server | ||
const fs = require('fs'); | ||
fs.unlinkSync(path); | ||
// return image details | ||
return image; | ||
} | ||
); | ||
}; |
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 was deleted.
Oops, something went wrong.
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 = (req, file, cb) => { | ||
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') { | ||
cb(null, true); | ||
} else { | ||
cb(error, false); | ||
} | ||
}; | ||
|
||
const storage = multer.diskStorage({ | ||
destination: (req, file, cb) => { | ||
cb(null, 'uploads/'); | ||
}, | ||
filename: (req, file, cb) => { | ||
cb(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); | ||
} | ||
}; | ||
|
||
export default { profileChecks }; |
This file was deleted.
Oops, something went wrong.
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,24 @@ | ||
import express from 'express'; | ||
import authenticationValidator from '../../validators/user.validator'; | ||
import authenticationController from '../../controllers/auth.controllers'; | ||
import AuthenticationToken from '../../middlewares/auth.middleware'; | ||
import profileUpdateCheck from '../../middlewares/profileUpdateCheck.middleware'; | ||
import upload from '../../middlewares/imageUpload.middleware'; | ||
const { login, signUp, profileUpdate } = authenticationController; | ||
const { validator, checkValidationResult } = authenticationValidator; | ||
const { verifyToken } = AuthenticationToken; | ||
const { profileChecks } = profileUpdateCheck; | ||
|
||
const router = express.Router(); | ||
router | ||
.post('/signup', validator('signup'), checkValidationResult, signUp) | ||
.post('/login', validator('login'), checkValidationResult, login); | ||
router.put( | ||
'/profileupdate', | ||
verifyToken, | ||
upload.single('image'), | ||
profileChecks, | ||
profileUpdate | ||
); | ||
|
||
export default router; |
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.