Skip to content

Commit cfe78b7

Browse files
committed
Refactoring...
1 parent e90ddbc commit cfe78b7

File tree

90 files changed

+1897
-1304
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

90 files changed

+1897
-1304
lines changed

.eslintrc.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ rules:
1313
no-bitwise: off
1414
no-unused-expressions: off
1515
no-case-declarations: off
16+
camelcase: off
1617
globals:
1718
process: on
1819
describe: on

package.json

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -17,28 +17,28 @@
1717
"docs": "apidoc -i src/controllers -o doc/"
1818
},
1919
"dependencies": {
20-
"axios": "^0.17.0",
20+
"axios": "^0.17.1",
2121
"bluebird": "^3.5.1",
2222
"body-parser": "^1.18.2",
2323
"compression": "^1.7.1",
24-
"connect-redis": "^3.3.2",
24+
"connect-redis": "^3.3.3",
2525
"cors": "^2.8.4",
2626
"debug": "^3.1.0",
2727
"dotenv": "^4.0.0",
28-
"exceljs": "^0.6.2",
28+
"exceljs": "^0.8.2",
2929
"express": "5.0.0-alpha.6",
3030
"express-fileupload": "^0.3.0",
3131
"express-graphql": "^0.6.11",
3232
"express-session": "^1.15.6",
3333
"flash": "^1.1.0",
34-
"github": "^12.0.1",
35-
"graphql": "^0.11.7",
36-
"graphql-compose": "^2.9.6",
37-
"graphql-compose-mongoose": "^1.9.4",
38-
"helmet": "^3.9.0",
34+
"github": "^13.1.0",
35+
"graphql": "^0.12.3",
36+
"graphql-compose": "^2.10.1",
37+
"graphql-compose-mongoose": "^1.10.0",
38+
"helmet": "^3.10.0",
3939
"make-dir": "^1.1.0",
40-
"moment": "^2.19.1",
41-
"mongoose": "^4.13.0",
40+
"moment": "^2.20.1",
41+
"mongoose": "^5.0.1",
4242
"morgan": "^1.9.0",
4343
"passport": "^0.4.0",
4444
"passport-github": "^1.1.0",
@@ -54,15 +54,15 @@
5454
"chai": "^4.1.2",
5555
"chai-as-promised": "^7.1.1",
5656
"codeclimate-test-reporter": "^0.5.0",
57-
"cross-env": "^5.1.1",
57+
"cross-env": "^5.1.3",
5858
"dotenv-cli": "^1.4.0",
59-
"eslint": "^4.10.0",
59+
"eslint": "^4.16.0",
6060
"eslint-config-airbnb-base": "^12.1.0",
6161
"eslint-plugin-import": "^2.8.0",
62-
"got": "^7.1.0",
63-
"mocha": "^4.0.1",
64-
"nodemon": "^1.12.1",
65-
"nyc": "^11.3.0"
62+
"got": "^8.0.3",
63+
"mocha": "^5.0.0",
64+
"nodemon": "^1.14.11",
65+
"nyc": "^11.4.1"
6666
},
6767
"engines": {
6868
"node": ">=7.6.0"

src/app.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ debug('bootstrapping application');
1313

1414
const config = require('./config');
1515
const Env = require('./config/env');
16-
const routes = require('./routes');
16+
const routes = require('./routes/index.routes');
1717

1818
/**
1919
* @param {Number} [port]

src/config/mongoose.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ mongoose.set('debug', Env.NODE_ENV === 'development');
1515

1616
const connect = () => mongoose.connect(url, {
1717
reconnectTries: Number.MAX_VALUE,
18-
useMongoClient: true,
1918
}).then((conn) => {
2019
initialized = true;
2120
return conn;

src/config/passport.js

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,19 @@ const passport = require('passport');
33
const GitHubStrategy = require('passport-github').Strategy;
44

55
const Env = require('./env');
6-
const RedisProvider = require('../providers/redis');
7-
const AuthService = require('../services/auth');
8-
const User = require('../models/user');
6+
const RedisProvider = require('../providers/redis.provider');
7+
const AuthService = require('../services/auth.service');
8+
const User = require('../models/v1/profile.v1.model');
9+
10+
const _validateUserCompany = async (accessToken, cb) => {
11+
const request = await AuthService.buildGitHubRequest(accessToken);
12+
const orgs = await request.get('https://api.github.com/user/orgs');
13+
14+
if (orgs.data) {
15+
const org = orgs.data.find(o => o.login === Env.GITHUB_COMPANY_NAME);
16+
if (!org) return cb(new Error('User must be in the allowed company'));
17+
}
18+
};
919

1020
passport.serializeUser((user, done) => {
1121
done(null, user._id);
@@ -29,6 +39,7 @@ passport.use('github-token', new GitHubStrategy({
2939
scope: ['user:email', 'read:org', 'repo'],
3040
}, async (accessToken, refreshToken, profile, cb) => {
3141
try {
42+
await _validateUserCompany(accessToken, cb);
3243
await AuthService.persistToken(accessToken, profile, 'github');
3344
cb();
3445
} catch (err) {
@@ -37,19 +48,15 @@ passport.use('github-token', new GitHubStrategy({
3748
}));
3849

3950
passport.use(new GitHubStrategy({
40-
clientID: Env.GITHUB_USERS_CLIENT_ID,
41-
clientSecret: Env.GITHUB_USERS_CLIENT_SECRET,
51+
clientID: Env.GITHUB_CLIENT_ID,
52+
clientSecret: Env.GITHUB_CLIENT_SECRET,
4253
callbackURL: `${Env.APP_URL}/auth/github/callback`,
4354
scope: ['user:email', 'read:org', 'repo'],
4455
}, async (accessToken, refreshToken, profile, cb) => {
4556
try {
57+
await _validateUserCompany(accessToken, cb);
58+
4659
const email = profile.emails.find(email => email.primary).value;
47-
const request = await AuthService.buildGitHubRequest(accessToken);
48-
const orgs = await request.get('https://api.github.com/user/orgs');
49-
if (orgs.data) {
50-
const org = orgs.data.find(o => o.login === Env.GITHUB_COMPANY_NAME);
51-
if (!org) return cb(new Error('User must be in the allowed company'));
52-
}
5360

5461
let user = await User.findOne({ email }).exec();
5562
if (!user) {

src/controllers/auth.js renamed to src/controllers/auth.controller.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
const debug = require('debug')('github-metrics:controllers:auth');
22
const passport = require('passport');
33

4-
const AuthService = require('../services/auth');
4+
const AuthService = require('../services/auth.service');
55

66
const AuthController = {
77

src/controllers/process.js

Lines changed: 0 additions & 40 deletions
This file was deleted.

src/controllers/sheet.js

Lines changed: 0 additions & 45 deletions
This file was deleted.

0 commit comments

Comments
 (0)