-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feature-[167573194]: build out signup endpoint
- Enable user sign up feature - Write unit and integration tests for feature [Deivers #167573194]
- Loading branch information
Showing
22 changed files
with
474 additions
and
15 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import bcrypt from 'bcryptjs'; | ||
import models from '../database/models'; | ||
import { | ||
serverResponse, | ||
serverError, | ||
checkEmail, | ||
checkUserName | ||
} from '../helpers'; | ||
|
||
const { User } = models; | ||
|
||
/** | ||
* @export | ||
* @class Users | ||
*/ | ||
class Users { | ||
/** | ||
* @name signUp | ||
* @async | ||
* @static | ||
* @memberof Users | ||
* @param {Object} req express request object | ||
* @param {Object} res express response object | ||
* @returns {JSON} JSON object with details of new user | ||
*/ | ||
static async signUp(req, res) { | ||
try { | ||
const { password, confirmPassword } = req.body; | ||
if (password !== confirmPassword) { | ||
return serverResponse(res, 400, { error: 'Passwords do not match' }); | ||
} | ||
if (await checkEmail(req.body.email)) { | ||
return serverResponse(res, 409, { error: 'Email already in use' }); | ||
} | ||
if (await checkUserName(req.body.userName)) { | ||
return serverResponse(res, 409, { error: 'Username already in use' }); | ||
} | ||
const hashedPassword = await bcrypt.hash(password, 10); | ||
const user = await User.create({ | ||
...req.body, | ||
password: hashedPassword | ||
}); | ||
delete user.dataValues.password; | ||
// const token = await generateToken(user.id); | ||
return serverResponse(res, 201, { user }); | ||
} catch (error) { | ||
return serverError(res); | ||
} | ||
} | ||
} | ||
|
||
export default Users; |
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,38 @@ | ||
export default { | ||
up: (queryInterface, Sequelize) => queryInterface.createTable('Users', { | ||
id: { | ||
allowNull: false, | ||
autoIncrement: true, | ||
primaryKey: true, | ||
type: Sequelize.INTEGER | ||
}, | ||
firstName: { | ||
type: Sequelize.STRING, | ||
allowNull: false | ||
}, | ||
lastName: { | ||
type: Sequelize.STRING, | ||
allowNull: false | ||
}, | ||
userName: { | ||
type: Sequelize.STRING, | ||
unique: true | ||
}, | ||
email: { | ||
type: Sequelize.STRING, | ||
unique: true | ||
}, | ||
password: { | ||
type: Sequelize.STRING | ||
}, | ||
createdAt: { | ||
allowNull: false, | ||
type: Sequelize.DATE | ||
}, | ||
updatedAt: { | ||
allowNull: false, | ||
type: Sequelize.DATE | ||
} | ||
}), | ||
down: queryInterface => queryInterface.dropTable('Users') | ||
}; |
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,17 @@ | ||
export default (sequelize, DataTypes) => { | ||
const User = sequelize.define( | ||
'User', | ||
{ | ||
firstName: DataTypes.STRING, | ||
lastName: DataTypes.STRING, | ||
userName: DataTypes.STRING, | ||
email: DataTypes.STRING, | ||
password: DataTypes.STRING | ||
}, | ||
{} | ||
); | ||
User.associate = () => { | ||
// associations can be defined here | ||
}; | ||
return User; | ||
}; |
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,19 @@ | ||
export default { | ||
up: queryInterface => queryInterface.bulkInsert( | ||
'Users', | ||
[ | ||
{ | ||
firstName: 'Abiola', | ||
lastName: 'JayZ', | ||
userName: 'JhayX', | ||
email: 'abiola.jz@andela.com', | ||
password: 'incorrect', | ||
createdAt: new Date(), | ||
updatedAt: new Date() | ||
} | ||
], | ||
{} | ||
), | ||
|
||
down: queryInterface => queryInterface.bulkDelete('Users', null, {}) | ||
}; |
Oops, something went wrong.