Skip to content

Commit

Permalink
chore(refactor): refactor codebase
Browse files Browse the repository at this point in the history
- ensure that there are minimal errors

[Finishes #164376263]
  • Loading branch information
Chrismarcel committed Mar 4, 2019
1 parent b32871c commit ef2c3b4
Show file tree
Hide file tree
Showing 8 changed files with 57 additions and 40 deletions.
35 changes: 29 additions & 6 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,34 @@
"consistent-return": 0,
"no-param-reassign": 0,
"comma-dangle": 0,
"curly": ["error", "multi-line"],
"import/no-unresolved": [2, { "commonjs": true }],
"no-shadow": ["error", { "allow": ["req", "res", "err"] }],
"function-paren-newline": ["error", "never"],
"curly": [
"error",
"multi-line"
],
"import/no-unresolved": [
2,
{
"commonjs": true
}
],
"no-shadow": [
"error",
{
"allow": [
"req",
"res",
"err"
]
}
],
"function-paren-newline": [
"error",
"never"
],
"indent": [
2,
2
],
"valid-jsdoc": [
"error",
{
Expand All @@ -41,6 +65,5 @@
"parserOptions": {
"ecmaVersion": 2017,
"sourceType": "module"
},
"parser": "babel-eslint"
}
}
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
"reset:db": "npm run sequelize db:migrate:undo:all && npm run sequelize db:migrate",
"start:dev": "npm run reset:db && npm run dev",
"build": "rm -rf dist && mkdir dist && babel -d ./dist ./server -s",
"heroku-postbuild": "NPM_CONFIG_PRODUCTION=false npm run build"
"heroku-postbuild": "NPM_CONFIG_PRODUCTION=false npm run build",
"lint": "eslint ./server --fix"
},
"lint-staged": {
"*.js": [
Expand Down
10 changes: 6 additions & 4 deletions server/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,15 @@ app.use(bodyParser.json());
app.use(passport.initialize());

// Creating user session
app.use(expressSession(
{ secret: process.env.SESSION_SECRET, resave: true, saveUninitialized: true }
));
app.use(expressSession({
secret: process.env.SESSION_SECRET,
resave: true,
saveUninitialized: true
}));

// Setup a default catch-all route that sends back a welcome message in JSON format.
app.get('/', (req, res) => res.status(200).send({
message: 'Authors Haven.',
message: 'Authors Haven.'
}));

// Routes
Expand Down
19 changes: 9 additions & 10 deletions server/controllers/user.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import '@babel/polyfill';
import dotenv from 'dotenv';
import db from '../database/models';
import { HelperUtils } from '../utils';
import HelperUtils from '../utils';
import response from '../utils/response';
import verifyEmailMarkup from '../utils/markups/emailVerificationMarkup';
import passwordResetMarkup from '../utils/markups/passwordResetMarkup';
Expand Down Expand Up @@ -33,15 +33,14 @@ export default class Users {
const formInputs = { ...body, password: hash };
try {
const createUser = await User.create(formInputs);

const encryptDetails = {
id: createUser.id, firstname, lastname, username, email
};
const token = await HelperUtils.generateToken(encryptDetails);

const name = typeof username !== 'undefined' ? username : `${lastname}, ${firstname}`;

await HelperUtils.sendMail(email,
const token = HelperUtils.generateToken({
...formInputs,
id: createUser.id
});
const name = typeof username !== 'undefined'
? username
: `${lastname}, ${firstname}`;
HelperUtils.sendMail(email,
'Authors Haven <no-reply@authorshaven.com>',
'Email Verification',
'Verify Email',
Expand Down
24 changes: 8 additions & 16 deletions server/routes/profile.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,31 +5,23 @@ import { AuthenticateUser } from '../middlewares';
const profileRoutes = express.Router();

// Fetch all users following you
profileRoutes.get(
'/profiles/followers',
profileRoutes.get('/profiles/followers',
AuthenticateUser.verifyUser,
Follow.fetchFollowers
);
Follow.fetchFollowers);

// Fetch all users your're following
profileRoutes.get(
'/profiles/following',
profileRoutes.get('/profiles/following',
AuthenticateUser.verifyUser,
Follow.fetchFollowing
);
Follow.fetchFollowing);

// Follow a particular user
profileRoutes.post(
'/profiles/:username/follow',
profileRoutes.post('/profiles/:username/follow',
AuthenticateUser.verifyUser,
Follow.followUser
);
Follow.followUser);

// Unfollow a particular user
profileRoutes.delete(
'/profiles/:username/follow',
profileRoutes.delete('/profiles/:username/follow',
AuthenticateUser.verifyUser,
Follow.unfollowUser
);
Follow.unfollowUser);

export default profileRoutes;
2 changes: 1 addition & 1 deletion server/test/follow.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import chaiHttp from 'chai-http';
import chai, { expect } from 'chai';
import dotenv from 'dotenv';
import app from '../app';
import { HelperUtils } from '../utils';
import HelperUtils from '../utils';

dotenv.config();
chai.use(chaiHttp);
Expand Down
2 changes: 1 addition & 1 deletion server/test/user.spec.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import chaiHttp from 'chai-http';
import chai, { expect } from 'chai';
import dotenv from 'dotenv';
import { HelperUtils } from '../utils';
import HelperUtils from '../utils';
import app from '../app';

dotenv.config();
Expand Down
2 changes: 1 addition & 1 deletion server/utils/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
import HelperUtils from './HelperUtils';

export { HelperUtils };
export default HelperUtils;

0 comments on commit ef2c3b4

Please sign in to comment.