-
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
20 changed files
with
433 additions
and
8 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
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,47 @@ | ||
import models from '../database/models'; | ||
// import { generateToken, serverResponse, serverError } from '../helpers'; | ||
import { serverResponse, serverError } from '../helpers'; | ||
import hashPassword from '../helpers/passwords'; | ||
|
||
const { User } = models; | ||
|
||
/** | ||
* @export | ||
* @class User | ||
*/ | ||
class Users { | ||
/** | ||
* @name signUp | ||
* @async | ||
* @static | ||
* @memberof User | ||
* @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 { email, userName, password } = req.body; | ||
const existingEmail = await User.findOne({ where: { email } }); | ||
const existingUserName = await User.findOne({ where: { userName } }); | ||
if (existingEmail) { | ||
return serverResponse(res, 409, { error: 'Email already exists' }); | ||
} | ||
if (existingUserName) { | ||
return serverResponse(res, 409, { error: 'Username already exists' }); | ||
} | ||
const hashedPassword = await hashPassword(password); | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
module.exports = { | ||
up: (queryInterface, Sequelize) => queryInterface.createTable('Users', { | ||
id: { | ||
allowNull: false, | ||
autoIncrement: true, | ||
primaryKey: true, | ||
type: Sequelize.INTEGER | ||
}, | ||
firstName: { | ||
type: Sequelize.STRING | ||
}, | ||
lastName: { | ||
type: Sequelize.STRING | ||
}, | ||
userName: { | ||
type: Sequelize.STRING | ||
}, | ||
email: { | ||
type: Sequelize.STRING | ||
}, | ||
password: { | ||
type: Sequelize.STRING | ||
}, | ||
createdAt: { | ||
allowNull: false, | ||
type: Sequelize.DATE | ||
}, | ||
updatedAt: { | ||
allowNull: false, | ||
type: Sequelize.DATE | ||
} | ||
}), | ||
down: (queryInterface, Sequelize) => 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 @@ | ||
module.exports = (sequelize, DataTypes) => { | ||
const User = sequelize.define( | ||
'User', | ||
{ | ||
firstName: DataTypes.STRING, | ||
lastName: DataTypes.STRING, | ||
userName: DataTypes.STRING, | ||
email: DataTypes.STRING, | ||
password: DataTypes.STRING | ||
}, | ||
{} | ||
); | ||
User.associate = function (models) { | ||
// 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 @@ | ||
module.exports = { | ||
up: (queryInterface, Sequelize) => 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.