Skip to content

Commit

Permalink
Merge 8e6cac7 into 14322ad
Browse files Browse the repository at this point in the history
  • Loading branch information
henryade committed Jul 30, 2019
2 parents 14322ad + 8e6cac7 commit 86bdae0
Show file tree
Hide file tree
Showing 23 changed files with 562 additions and 18 deletions.
4 changes: 1 addition & 3 deletions .hound.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
javascript:
enabled: false
eslint:
enabled: true
config_file: .eslintrc
config_file: .eslintrc.json
ignore_file: .eslintignore
2 changes: 1 addition & 1 deletion .sequelizerc
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ const path = require('path');
module.exports = {
'config': path.resolve('server/database/config', 'config.js'),
'models-path': path.resolve('server/database/models'),
'seeds-path': path.resolve('server/database/seeds'),
'seeders-path': path.resolve('server/database/seeds'),
'migrations-path': path.resolve('server/database/migrations')
}
103 changes: 96 additions & 7 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 7 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@
"coverage": "nyc report --reporter=text-lcov | coveralls",
"db:migrate": "sequelize db:migrate",
"db:migrate-undo": "sequelize db:migrate:undo:all",
"db:rollback": "npm run db:back && npm run db:roll && npm run db:seed",
"db:rollback": "npm run db:migrate-undo && npm run db:migrate && npm run db:seed",
"db:seed": "sequelize db:seed:all",
"start": "node dist/index.js",
"start:dev": "cross-env NODE_ENV=development DEBUG=dev nodemon --exec babel-node server",
"test": "nyc mocha --timeout 1000 -r esm --exit"
"test": "npm run db:rollback && nyc mocha --timeout 1000 -r esm --exit"
},
"husky": {
"hooks": {
Expand All @@ -26,18 +26,20 @@
"author": "Andela Simulations Programme",
"license": "MIT",
"dependencies": {
"bcryptjs": "^2.4.3",
"coveralls": "^3.0.5",
"debug": "^4.1.1",
"dotenv": "^8.0.0",
"express": "^4.17.1",
"morgan": "^1.9.1",
"swagger-ui-express": "^4.0.7",
"yamljs": "^0.3.0",
"pg": "^7.11.0",
"pg-hstore": "^2.3.3",
"sequelize": "^5.10.2",
"sequelize-cli": "^5.5.0",
"sqlite3": "^4.0.9"
"sinon": "^7.3.2",
"sqlite3": "^4.0.9",
"swagger-ui-express": "^4.0.7",
"yamljs": "^0.3.0"
},
"devDependencies": {
"@babel/cli": "^7.5.5",
Expand Down
50 changes: 50 additions & 0 deletions server/controllers/user.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import helpers from '../helpers';

const {
comparePassword, findUser, serverResponse, serverError
} = helpers;
// const {
// comparePassword, findUser, generateToken, serverResponse, serverError
// } = helpers;
/**
*
*
* @class User
*/
class User {
/**
*
*
* @static
* @param {object} req - request object
* @param {object} res - response object
* @memberof User
* @returns {json} object
*/
static async login(req, res) {
try {
const { userLogin, password } = req.body;
if (!/\D/.test(userLogin)) {
return serverResponse(res, 400, {
message: 'user login must be a string'
});
}
const user = await findUser(userLogin);
let verifyPassword;
if (user) verifyPassword = await comparePassword(password, user.password);
if (!user || !verifyPassword) {
return serverResponse(res, 403, {
message: 'incorrect username or password'
});
}
const { dataValues } = user;
// const token = generateToken(id);
delete dataValues.password;
return serverResponse(res, 200, { user: { ...dataValues } });
} catch (error) {
serverError(res);
}
}
}

export default User;
64 changes: 64 additions & 0 deletions server/database/migrations/20190729172658-create-user.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
module.exports = {
up: (queryInterface, Sequelize) => queryInterface.createTable('Users', {
id: {
allowNull: false,
autoIncrement: true,
primaryKey: true,
type: Sequelize.INTEGER
},
firstName: {
allowNull: false,
type: Sequelize.STRING
},
lastName: {
allowNull: false,
type: Sequelize.STRING
},
userName: {
allowNull: false,
unique: true,
type: Sequelize.STRING
},
email: {
allowNull: false,
unique: true,
type: Sequelize.STRING
},
password: {
allowNull: false,
type: Sequelize.STRING
},
avatarUrl: {
allowNull: false,
type: Sequelize.STRING
},
facebookId: {
type: Sequelize.BIGINT
},
googleId: {
type: Sequelize.BIGINT
},
twitterId: {
type: Sequelize.BIGINT
},
verified: {
allowNull: false,
type: Sequelize.BOOLEAN,
defaultValue: false
},
status: {
allowNull: false,
type: Sequelize.STRING,
defaultValue: 'active'
},
createdAt: {
allowNull: false,
type: Sequelize.DATE
},
updatedAt: {
allowNull: false,
type: Sequelize.DATE
}
}),
down: queryInterface => queryInterface.dropTable('Users')
};
3 changes: 2 additions & 1 deletion server/database/models/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* istanbul ignore file */
import fs from 'fs';
import path from 'path';
import Sequelize from 'sequelize';
Expand Down Expand Up @@ -36,4 +37,4 @@ Object.keys(db).forEach((modelName) => {
db.sequelize = sequelize;
db.Sequelize = Sequelize;

module.exports = db;
export default db;
23 changes: 23 additions & 0 deletions server/database/models/user.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
module.exports = (sequelize, DataTypes) => {
const User = sequelize.define(
'User',
{
firstName: DataTypes.STRING,
lastName: DataTypes.STRING,
userName: DataTypes.STRING,
email: DataTypes.STRING,
password: DataTypes.STRING,
avatarUrl: DataTypes.STRING,
facebookId: DataTypes.BIGINT,
googleId: DataTypes.BIGINT,
twitterId: DataTypes.BIGINT,
verified: DataTypes.BOOLEAN,
status: DataTypes.STRING
},
{}
);
User.associate = (models) => {
// associations can be defined here
};
return User;
};
Loading

0 comments on commit 86bdae0

Please sign in to comment.