-
Notifications
You must be signed in to change notification settings - Fork 1
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
12 changed files
with
233 additions
and
25 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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
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,6 @@ | ||
const basePath = (req) => { | ||
const path = `${req.protocol}://${req.headers.host}`; | ||
return path; | ||
}; | ||
|
||
export default basePath; |
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,58 @@ | ||
import Response from '../helpers/response'; | ||
|
||
const minPassLen = 5; | ||
let response; | ||
const userTypeOptions = ['user', 'artist']; | ||
/** | ||
* A module that checks if email already exists at sign up | ||
* @module validateUserInputs | ||
*/ | ||
class UserValidator { | ||
/** | ||
* @description - Checks the request parameters for user reg | ||
* @param {Object} req - request | ||
* @param {object} res - response | ||
* @param {Object} next - Call back function | ||
* @return {object} - status code and error message or next() | ||
* @static | ||
* @memberof UserValidator | ||
*/ | ||
static UserSignUpValidator(req, res, next) { | ||
req.check('firstName', 'First Name is required').trim().notEmpty(); | ||
req.check('lastName', 'Last Name is required').trim().notEmpty(); | ||
req.check('username', 'Username is required').trim().notEmpty(); | ||
req.check('userType', 'User type is required').trim().notEmpty(); | ||
req.check('email', 'Email is required').trim().notEmpty(); | ||
req.check('email', 'Email is not valid').trim().isEmail(); | ||
req.check('password', 'Password is required').trim().notEmpty(); | ||
req.check('password', 'Minimum password length is 5 characters') | ||
.isLength({ min: minPassLen }); | ||
const errors = req.validationErrors(); | ||
const validationErrors = []; | ||
if (errors) { | ||
errors.map(err => validationErrors.push(err.msg)); | ||
response = new Response( | ||
'Bad Request', | ||
400, | ||
'Invalid credentials', | ||
validationErrors | ||
); | ||
return res.status(response.code).json(response); | ||
} | ||
const { userType } = req.body; | ||
const userTypes = userTypeOptions.includes(userType); | ||
if (!userTypes) { | ||
response = new Response( | ||
'Not found', | ||
404, | ||
'This user type does not exist' | ||
); | ||
return res.status(response.code).json(response); | ||
} | ||
const { email } = req.body; | ||
req.body.email = email.replace(/\s{1,}/g, '').trim().toLowerCase(); | ||
return next(); | ||
} | ||
} | ||
|
||
export default UserValidator; |
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,35 @@ | ||
import models from '../db/models'; | ||
import Response from '../helpers/response'; | ||
|
||
let response; | ||
/** | ||
* A module that checks if email already exists at sign up | ||
* @module emailCheck | ||
*/ | ||
|
||
/** | ||
* @param {object} req The request object | ||
* @param {object} res The response object | ||
* @param {Function} next The next function to be executed | ||
* @return {void} | ||
*/ | ||
const emailCheck = async (req, res, next) => { | ||
const { email } = req.body; | ||
|
||
const emailExist = await models.User.find({ | ||
where: { | ||
email, | ||
}, | ||
}); | ||
if (emailExist) { | ||
response = new Response( | ||
'Unsuccessful', | ||
409, | ||
'Email already exists. Input a different email' | ||
); | ||
return res.status(response.code).json(response); | ||
} | ||
if (!emailExist) next(); | ||
}; | ||
|
||
export default emailCheck; |
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
Oops, something went wrong.